JavaScript - 2 Questions
1. I am in the midst of making a website and doing a few things but am thinking of adding a log in section for members can i put a password directly on a video file? or do i have to do it to the page?
2. Also looking for a good provider to upload my site to, what does everything suggest for this? Thanks Similar TutorialsHi again, I have 2 new questions for you all! 1.) *RESOLVED* 2.) So in this form: Code: <form name="form" action="email.php" method="post"> <div id="dynamicInput"> <br> <input type="checkbox" name="1" /><input type="text" name="i[]"> </div> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');"> <br> <input name="email" type="text"> <br /> A12098 <input name="verify" type="text"> <input name="submit" type="submit"> </form> I have a button that will add a form element to the form. In this case, it adds a checkbox and a text box. The name on the checkbox goes up from 1-30 (thats the max amount of fields that can be added) and the text box has a name of i[]. Is it possible for the user to click on the checkbox and the corresponding text box (the one next to the checkbox) will be disabled so editing is stopped? Then they could un-click it and it would be editable again. Thanks in advance! JavaScript functions must be called: A. from the server B. implicitly C. explicitly D. A and C, but not B. E. None of the above. JavaScript commands written outside of a function will be executed: A. by the server. B. implicitly. C. explicitly. D. never, they are ignored. E. None of the above. The best loop for iterating through an array is A. Enhanced For loop B. While C. Do Until D. Do While. E. None of the Above. JavaScript Arrays are always passed to functions? A. By Reference. B. By Value. C. Globally. D. As a string. E. None of the Above. The best way to execute JavaScript code when you first bring up a page is: A. onload event B. JavaScript code outside of any function. C. onstart event. D. All of the above. E. None of the Above. Write a JavaScript function to handle a callback: Assume the following input fields: <input type="text" id="lastName" name="lastName" /> <input type="text" id="firstName" name="firstName" /> <input type="text" id="phone" name="phone" /> <input type="text" id="email" name="email" /> A callback function will receive a pipe delimited string from the server as such: Last-name|first-name|phone#|email Example: Doe|Jane|415-555-1212|jane.doe@gmail.com The callback function is: function customer_Callback ( content ) { // use the split method to convert content to an array. // use document.getElementById() to get each of the above input fields. // populate from the array. } ----------------------------------------- I am having serious trouble with these problems, I beseech you! There will be a special prize to whoever answers correctly all these questions first. Thanks! 1. I want to make form with 2 select filds that one of them will be disabled if in the first the use choose a specific option i wrote it in this way (but its not work) how I fix it? Code: <script type="text/javascript"> function itay() { if (document.some1.one.value="x") document.some1.two.disabled=true if (document.some1.one.value="y") document.some1.two.disabled=false } </script> </head> <body bgcolor="#FFFFFF"> <form name="some1"> <table> <tr> <td> <select id="one" onclick="itay()"> <option value="x">x</option> <option value="y">y</option> </select> </td> <td> <select id="two"> <option value="a">a</option> <option value="b">b</option> </select> </td> </tr> </table> </form> 2. I want that after u fill the form and press submit u will see a txtarea with all the options u selected (for confirm that you chose the right things) and then press submit agien and get all the things u saw in the txtarea to a Email. (Hope u understand ) so how I do it? Hey everyone. I am very new at JavaScript and I need some help. I want to have a section on my home page where a person can choose a bike by clicking on a couple of arrows on the right and left ends of the bike. I want something similar to this type of program. http://qlpros.com/ I don't want a border around the bike. I have been looking for a couple hours now and I haven't found anything. Any help would be much appreciated!! My other question is how to transfer javascript to an external style sheet in dreamweaver. Thanks!! I am not understanding something here with this: http://www.w3schools.com/jquery/jquery_ajax.asp Code: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("div").load('test1.txt'); }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html> When you click on the button, AJAX changes the text : Code: Let AJAX change this text to: Code: AJAX is not a programming language. It is just a technique for creating better and more interactive web applications. My question is, where is this text above located since it's not in the code? Also, if I wish to change the text mentioned, how can I do so please? Hi, I am currently having a problem with my code. It is pointing at a logical error somewhere as neither the error console in FireFox nor Firebug can detect any errors. The problem is getting the alert box to pop up when the user types in invalid letters or numbers for their respective functions. I guess it could be the Unicode coding for Internet Explorer or Mozilla, or maybe the validation is not getting called from the option list....Anyway here's my code so far: <script type="text/javascript"> /* <![CDATA[ */ function validateAlphabetic(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\D/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter an alphabetic value."; } catch(inputError) { window.alert("You can only enter letters into this field."); retValue = false; } finally { return retValue; } } function validateNumeric(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\d/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter a numeric value."; } catch(inputError) { window.alert("You can only enter numbers into this field."); retValue = false; } finally { return retValue; } } /* ]]> */ </script> </head> <body> <h1>Challenge Questions</h1> <form action="" enctype="application/x-www-form-urlencoded"> <select> <option value="maiden" onkeypress="return validateAlphabetic(event)">What is your mother's maiden name</option> <option value="pet" onkeypress="return validateAlphabetic(event)">What is the name of your favorite pet?</option> <option value="city" onkeypress="return validateAlphabetic(event)">What city were your born in?</option> <option value="security" onkeypress="return validateNumeric(event)">What is your social security number?</option> <option value="siblings" onkeypress="return validateNumeric(event)">How many siblings do you have?</option> </select><br /> <input type="text" size="25" /> </form> </body> Reply With Quote Ok, so I have a couple of questions about JavaScript that I would like answered by the programming gurus on this forum, please. Firstly, I have an idea for an online text-based role-playing game (games like GangsterParadise, etc.), and I am wondering, is it possible (or advisable?) to create the site using nothing but HTML, CSS and JavaScript? Can it be done, and if so, are there any downsides to doing this? I have heard using strictly JavaScript as a programming language on its own, on a site where members will have their own password-protected accounts, should not be done, as there are serious security flaws - is this true, and if so, why? Secondly, most JS programmers on the forum have probably digested and been through hundreds and hundreds of books on the subject since beginning to learn JavaScript - in your opinion, what are the best books to get hold of, for a relative beginner to JavaScript? What book makes the language easy to understand, and doesn't have you scratching your head to make sense of what it is saying? Thanks a lot in advance for the help, it's much appreciated. I'm researching a possible web project. The project will allow users to create and run JS online, similar to JSFiddle, Construct 2 and GameSalad. At this stage I'm just looking to gather general information. So my first question is, just how big of a project would that be? what web technologies would be needed? Would Node.Js be needed? or would PHP be ok for the backend? Thanks for any advice. Lately I've been doing some modding for a game called Minecraft which requires some programming in Java. I've been doing a lot of research but because I can't think of a simplified version of my questions it's hard to get any results from Google. So I'm hoping someone could answer these for me. If you can't, I would even appreciate being pointed in the right direction or led to some reading material that would answer these questions for me. 1) How can I add the value of a variable onto the name of another variable. For instance, I have this line of code Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); and this variable that will always be a number Code: private int numberA; I would like to add the value of numberA onto entityitem. So if numberA was 1 entityitem would become entityitem1. 2) What is the best variable type to store values such as Item.coal, which is an object within the game? Would a String type suffice? 3) Using the same code above: Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); How could I use a variable's value where Item.ingotIron is? I tried some different things but the compiler threw "ItemStack doesn't exist" or some error along those lines at me. For instance if variableA's value is Item.coal, how could I use that variables value where Item.ingotIron is. Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(variableA)); I appreciate your time and help on this issue and anything you can provide will be greatly appreciated. Hi all, This is a quickie. I'm a JavaScript newbie. I have had a crack programming with it but I need some questions answered to help my understanding. Please tell me the convention that governs the use of "" and '', because so many articles that I am finding in my learning journey are using them interchangeably and it is so confusing. For instance, but not limited to, take the id and value tags of an <input type=... of whatever. Is it best to use '' or "" for the labels you give? What is the convention governing the use of a ; (semicolon) because so many people use one where others do not. I'm under the impression it is an EOL terminator like in Bash, right? So it goes after declaring variables or after something within an if statement perhaps? Thanks QF 3 questions. I am very very new to JS (i am a html/css wiz but am just now learning js. I have taken 2 university CS courses but both were with C++)... My friend sent me these problems and wanted some help. Anyone here wanna give em a go? Given the string "Frank delete from users Beans" in a textfield If you find any sql token you find (like delete, drop, truncate, etc), strip it out, and regenerate the original string without those tokens; place the regenerated string (without the sql) back in the textfield. If You cannot strip out the sql and place the sanitized value back in the textfield, you will not get full credit for this question. Write a document that contains 5 paragraphs, and 4 headers. Create a script that finds all of them and puts "FOUND IT" beside it. Create a document that lets user's enter a planet's (like Jupiter, Saturn, Mars...) name (via a select or input field), and at the click of a button (or when the selected option was chosen), have the distance (from the Sun or Earth) appear next to that select box or textfield (which ever you choose to implement for the input from the user.) Please use Google to find the distances. HINT: use innerHTML = '...' Thanks guys! Hi All I have a xml string located in a hidden textbox that i need to parse how do i get it into a xml object I thought nievly i could xmlDoc = document.getElementById("XML").value alert(xmlDoc.getElementsByTagName("SupplMets")[0]); document.write("<table border='1'>"); but obviously i need to do some more work to get it into an xml object ...any ideas the end goal here is to get the data in the xml into a table here is what the xml string looks like <SupplMets TumorSupplementalId="272341"><SupplMet TumorSupplMetsId="109130" SiteOfMetastasis="C020" DateOfMetastasis="20010101" MetastasisIdType="" MetastasisEliminated="" MetastasisSD="02-003710" /></SupplMets> I am newbie in javascript. While being studying it I have not understood some concepts well. JS is prototype-based language, as in Java it has one main prototype Object, also there are some other widely used object, like Array, RegEx, String ...... . So I can access and inherit from this objects/prototypes. So the questions is where do this object (declarations) are stored ? They are also allocated in memory ? Or when JS sees that there is declaration of some object is present i script it reads from file or whatever ? When I am using Function with key word new, what happens. As far as function is also object, it has field prototype and when calling this function with new it returns object of prototype type ? Am I right ? So if I haven't specified prototype it will returns object of Object type ? How does javascript knows about real type of variable. For example when I use regexp, it has method exec. I can call it on every variable. But I guest if variable doesn't have this field it returns undefined ? So the question is how does JS determine what real type of variable is ? Where this information is stored ? Closure in JS. I don't understand this concept well. I think of it like reference count in Java (used or been used by Garbage Collector). If we have a least one reference to variable it will still exist and it doesn't matter where it was declared. So making getter method inside another func makes it exists in memory. If I am wrong please give good explanation of this. Does JS runs in its own virtual machine like Java ? Or browser plays this role. I guess if it has GC, since one process cannot access address space of another process it should be something like virtual machine which controls memory allocation. I would be very grateful for help. Thx in advance. Reply With Quote 01-21-2015, 10:44 AM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts Questions About Javascript - JavaScript | Dream.In.Code I know that global variables are properties of the window object... so does that mean that local variables are properties of the function they belong to? And does that mean that functions are methods of the window object and that nested functions are methods of the function they belong to?
Hey everyone, I have a survey that I have been developing (with the help of people from this forum among others) that is nearing completion but still has a couple things to be worked out using JavaScript. For reference, here is a link to the survey: http://wri.eas.cornell.edu/weed_survey_site/index2.html Here is one issue that I'm having and I would appreciate any help: 1. on line 111, the label, id and value for each input needs to increase by one (i.e <label for='ValidCheckbox_01'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_01' value= '1'>" + i + "</label>, <label for='ValidCheckbox_02'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_02' value= '2'>" + i + "</label>, etc.) for each additional label. Here is an example of a scrolling window and the codes about it: Code: HTML code: <html> <head> <title>A DOM Scrolling Window</title> <script language="Javascript" type="text/javascript" src="scroll.js"> </script> <link rel="stylesheet" type="text/css" href="scroll.css"> </head> <body> <h1>Scrolling Window Example</h1> <p>This example shows a scrolling window created using Javascript and the W3C DOM.The red-bordered window below is actually a layer that shows a clipped portion of a larger layer.</p> <div id="thewindow"> <div id="thetext"> <p> I want to make this text scroll horizontally in one line from left to right.Any suggestions? </p> </div> </div> </body> </html> Code: JS code: // global variable for position of the scrolling window var pos=100; function Scroll() { if (!document.getElementById) return; obj=document.getElementById("thetext"); pos -=1; if (pos < 0-obj.offsetHeight+130)return; obj.style.top=pos; window.setTimeout("Scroll();",30); } // Start scrolling when the page loads window.onload = Scroll; I have some questions about it: a)Can i move the text from top to the buttom?(which is the opposite from what it moves now). b)How can i make the text to move nonstop?In other words when it stops to start again. c)I have used the obj.style.left=pos in order to make the text move from left to right but i want it to move all horizontally in one line only.How could i do that?Something like this: This is a text.This is text.This is a text.This is a text... not like : <p> This is a text.This is a text.This is a text.This is a text... <p> Hello. I have a page that has bunch of moving elements, and obviously I want the movement to be smooth. It worked just great in chrome, but very chunky in firefox. I ran a profiler, found the bottleneck and dealt with it, so things work fine now, but after seeing the result of profiler I now have few questions: The function that is responsible for moving elements around takes 33% of time. Here's the code: Code: Tile.prototype.relocate=function(x,y){ this.elem.style.left=this.x=x; this.elem.style.top=this.y=y; } It's called from timer (setInterval) for elements that are not where they should be (they have .style.position set to "relative"). Is there a better way of moving elements around? Another function: Code: function type(code){ return code>>8; } It takes 13% of time. Now this is just ridiculous. 181854 binary shifts take 174.579ms. Is there a way to make it look like a function call but just replace the call with actual code at compile time, just like C's preprocessor? Hey, my names xzanth, I'm new here and I'm trying to get a javascript game server to work but have hit two slight snags. 1. I was wondering if there is a command that from within a .js file it can run an external, different .js file. 2. This is a rather lengthy one but I have an array, and I would like a section of code to be run whenever another value is added to this array. Much like Code: if (useradded) { command(user); } Thanks for the help, Xzanth I have been stuck on a few questions in my computer science class about javascript. I have read the entire chapter but I cannot find the answers to these questions. I believe that I have tryed every important word in every section of the chapter in all questions. I have used every source for this information available to me and after all of them found this website. This is probably extremely basic information but I am unable to solve it. The questions include(They were not numbered in assignment however I have numbered them to try and help): 1. The Graphics class method for displaying text is _________. 2 The applet or JFrame method that returns the Container object that represents the applet's (or JFrame's) space (its visual "real estate") is __________. 3. The import statement needed to use button components in applets or GUI applications is ________. 4. The general term for methods that are invoked as a result of a user action is __________. 5. Clicking a button results in the creation of an _____________ object to represent the button click. 6. Clicking a button may result in notification being sent to an ________ object. 7. The method used to arrange for a button to notify another object when it is clicked later is to an __________. 8. The class definition for objects that receive notifications of user operations on controls like buttons must contain the following phrase: __________. These questions are the last ones that I have left. I have tryed everything. I can submit answers as many times as I want, however there is a deadline. I have a few buttons on a page I'm developing and I want the onclick event to call a javascript function in an external file and execute it. I would like to be able to pass a parameter to that function and then either have the function take the user to a new URL or make changes to the webpage content. Initially (just to test) I had inline javascript that caused an alert to popup. That worked fine. Next I took the inline code and put it in a function in an external javascript file that was referenced in the HTML: Code: <script type="text/javascript" src="../assets/js/ews-js.js"></script> <a link="www.xx.com" class="sk-shop-button" onClick="onclick_shop_button">Shop for Supplies</a> The function is as follows: Code: function onclick_shop_button() { window.alert('Life Is Good!'); return false; } When I attempt to call it this way nothing happens. I'm guessing I should not be using a link there since I have to build the URL inside the Javascript (for now though the Javascript is just showing an alert). In one use case I want to be able to pass a parameter which would contain a product name so the function could load the correct webpage. So the function would have to build the URL using the product name as part of the URL then load that page. In a different use case (for a different button) the user would click on an EDIT button that would then update parts of the webpage allowing the user to click on areas to delete content. I am not sure how to implement either use case. I know I can use CSS to modify the look of the webpage and then use subsequent onclick events to do the deleting but am not sure how to delete HTML from within Javascript. Same with how to go to a new URL from within Javascript. Finally I am not sure why the inline Javascript works but the external does not. Any help would be GREATLY appreciated! |