JavaScript - Sync With Javascript Question
Hi,
I have a form with a input field(name) and a textarea(keywords). I am using the below code to sync the value of name with keywords. If additional keywords are added in the textarea and then the name field is altered all additional keywords are lost as they are overwritten by the name field sync. I would like to place a comma after the synced value and have whatever follows the comma to not be touched. Like this: Name: keyword1 Keywords: keyword1, keyword2, keyword3, etc. Could anyone point me in the right direction? Any help with this would be most appreciated. Code: var obj=document.getElementById('name'); var att = {"onkeyup":"sync()"}; for(var n in att) { obj.setAttribute(n, att[n]); } function sync() { var v1 = document.getElementById('name'); var v2 = document.getElementById('keywords'); v2.value = v1.value; } Similar TutorialsDoes anyone know a way to do vertical sync with javascript animations (getting timers to run on the vertical sync)? I rather doubt there is a way to do it, but I find it annoying that when I am dragging an object with my mouse that the object "tears" sometimes. I'm not really looking for someone to fix/answer this for me, but maybe give me a hit in the right direction. I need to fix this while loop to run correctly, but has errors in the code. This code is supposed to fill an array with numbers 1 through 100 and then print them. Here is the code: <script type="text/javascript"> /* <![CDATA[ */ var count = 0; var numbers = new Array(100); while (count < 100) { numbers[count] = count; ++count; } while (count < 100 ) { document.write(numbers[count]); ++count; } /* ]]> */ </script> What i am most confused about is this part of the code numbers[count] i don't understand what is going on there. Sorry i am very new to this. Any ideas would be appreciated thank you. I have an application that has a menu - one of the choices on that menu is "Contacts" - This menu is controlled by css - I've written a script that will modify the css style setting for "display" and "zindex" for the rule that controls the pull down for contacts - this worked for hover, but I am now trying to change to a click event - I successfully change the rule, but the menu doesn't display - not sure if I'm returning incorrectly form the javascript function or what - here's a code snippet: CSS: Code: .primaryNav .subMenu { background-color: #B0967E; position: absolute; width: 300px; left: 600px; /* 823px - 300px - 20 px + 97px */ padding: 10px; display: none; color: #fff; font-size: 90%; } Javascript: Code: <script type="text/javascript"> function SetDisplayCSS() { var mysheet=document.styleSheets[0]; var myrules=mysheet.cssRules? mysheet.cssRules[0].styleSheet.cssRules: mysheet.imports[0].rules; for (i=0; i<myrules.length; i++){ if(myrules[i].selectorText.toLowerCase()==".primarynav .submenu"){ //find "a:hover" rule targetrule=myrules[i]; alert("Rule is found"); break; } } targetrule.style.display = "block"; targetrule.style.zindex = "10"; alert(targetrule.selectorText); alert(targetrule.style.backgroundColor); alert(targetrule.style.position); alert(targetrule.style.width); alert(targetrule.style.left); alert(targetrule.style.padding); alert(targetrule.style.display); alert(targetrule.style.color); alert(targetrule.style.fontSize); alert(targetrule.style.zindex); return true; } </script> html Code (names have been changed to protect the innocent) - note the onclick event handler for the contacts menu option. Code: <li class="pn test"><a href="#" onclick="return SetDisplayCSS();" name="contacts">Contacts</a> <div class="subMenu"> <table width="100%"> <tbody> <col /> <col align="right" valign="top" /> <tr> <td><a href="mailto:abc@xxxxxxx.com">Service Requests</a></td> <td>555.555.5555</td> </tr> <tr> <td><a href="mailto:me@notreal.com">Bugs Bunny</a><br />Tenant Liaison</td> <td>555.555.555</td> </tr> <tr> <td><a href="mailto:blah@blah.com">blah blah</a><br />Client Services Manager</td> <td>123.456.1234</td> </tr> </tbody> </table> <p><a href="xxxxxxxx.htm" class="more">More Contacts...</a></p> </div> </li> Thanks for any help...... HI Guys!! My name is Megan and I am a college student in need of some JavaScript help for my computer science class!! My professor is making us complete some stupid class project for finals and I can't figure it out! He suggested that we may try to find a JavaScript Website to help us if we have trouble figuring out how to write the code. I have looked and looked and can't find out how to fix my code!! We have to write code to make a slot machine .. I have started the code based on what he gave us and have tried my hardest to figure out how to complete it but I do not know how to finish it. I have the images working correctly (kind of.. the second one seems to have problems loading? I dunno what I did to mess that up) and the counter working, but I need to make it add 13 credits when all 3 images are the same. I added code that I thought would work but it's not for some reason that I can't figure out. It should also pop up an alert screen when all 3 are correct and you win. I guess this would have to be including with the if statement and something like alert('You win 12 credits!!!') Lastly I need to add code that prevents the person from playing when the credit line is 0 (so you can't get - credits!) and I have no idea how to do this. Any help would be greatly appreciated! Here's what I have so far! HI Guys!! My name is Megan and I am a college student in need of some JavaScript help for my computer science class!! My professor is making us complete some stupid class project for finals and I can't figure it out! He suggested that we may try to find a JavaScript Website to help us if we have trouble figuring out how to write the code. I have looked and looked and can't find out how to fix my code!! We have to write code to make a slot machine .. I have started the code based on what he gave us and have tried my hardest to figure out how to complete it but I do not know how to finish it. I have the images working correctly (kind of.. the second one seems to have problems loading? I dunno what I did to mess that up) and the counter working, but I need to make it add 13 credits when all 3 images are the same. I added code that I thought would work but it's not for some reason that I can't figure out. It should also pop up an alert screen when all 3 are correct and you win. I guess this would have to be including with the if statement and something like alert('You win 12 credits!!!') Lastly I need to add code that prevents the person from playing when the credit line is 0 (so you can't get - credits!) and I have no idea how to do this. Any help would be greatly appreciated! Here's what I have so far! Code: <html> <head> <title> Slot Machine</title> <script type="text/javascript" src="http://balance3e.com/random.js"></script> <script type="text/javascript"> function SpinSlots() // Assumes: slot images are in http://balance3e.com/Images // Resultes: displays 3 random slot images { var slot1, slot2, slot3; slot1 = RandomOneOf(['lemon', 'cherry', 'bar']); slot2 = RandomOneOf(['lemon', 'cherry', 'bar']); slot3 = RandomOneOf(['lemon', 'cherry', 'bar']); document.getElementById('slot1Img').src = 'http://balance3e.com/Images/' + slot1 + '.jpg'; document.getElementById('slot2Img').src = 'http://balance3e.com/Images/' + slot2 + '.jgp'; document.getElementById('slot3Img').src = 'http://balance3e.com/Images/' + slot3 + '.jpg'; document.getElementById('credits').innerHTML = parseFloat(document.getElementById('credits').innerHTML) - 1; if (slot1 == slot2 == slot3) { document.getElementById('credits').innerHTML = parseFloat(document.getElementById('credits').innerHTML) + 13; } } </script> </head> <body> <div style="text-align:center"> <p> <img id="slot1Img" border=1 alt="slot image" src="http://balance3e.com/Images/cherry.jpg"> <img id="slot2Img" border=1 alt="slot image" src="http://balance3e.com/Images/lemon.jpg"> <img id="slot3Img" border=1 alt="slot image" src="http://balance3e.com/Images/bar.jpg"> </p> <input type="button" value="Click to Spin" onclick="SpinSlots();"> <p> Credits Remaining: <spin id="credits">20</span> </p> </div> </body> </html> Hey Guys, I was creating an image map with rollover images. I was just wondering if I could add a fade effect to the transition. The underarms is the only rollover that works at the moment. Please check the source code for the code because it's too long to post here. http://wedezign.com/chris/ I have a question about Javascript. Hello. I need help with JavaScript enabled. My job so that I can automatically send button to be pushed faster. I use google chrome. For example; Automatically have form filling add-ons. (Autofill), but only to fill the send button will not print. How can I do this automatically? Button codes; <input type='submit' name='post_shout' value='Shout' class='button' /> Google Chrome address bar: javascript: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx what I need to write here? Can I do it after 1-2 seconds and fill out? Many thanks in advance. (My English is poor) I am a newbie with a newbie question =) I recently took an exam type thing using my Firefox browser (v3.5.3). I still have my browser window open that I used, and when I press the back button on the browser I get a message "To display this page, Firefox must send information that will repeat any action ..." Is there any way (either disk or memory cache) to reload the pages with out having to resend the data, OR is there any way (hex editor) to view the exam (forms) questions?? Just curious, Thanks I'm trying to figure out this question that was assigned to me, as I haven't done alot on javascript before but I've tried to get most of this, I'm just not sure if this is correct. If anybody could help it would be greatly appreciated. The question is as follows: You are provided with a string array called country that contains the name of every country that the Ski Club visits. For example one element of this array might be as follows: country[0] = "Austria" Another array called villages contains strings with information on village names and altitude in a particular country. For example: villages[0] = "Austria:Seefield 850m*"; Write a JavaScript function snowReport(countryIndex) that will use the arrays provided to write a report of all villages that include a given country. The function will be passed an integer representing the index of an element of the country array. A match is found if the country appears in a string (Hint use appropriate JavaScript function to evaluate if a country name is contained in a village string.) All matching villages should be displayed. Output should be displayed in the villages div element you defined in part (a). Output is shown for a search for Austria in Figure 1b. <script type="text/javascript"> function makeArray() { var country = new Array(5); country[0] = "Austria"; country[1] = "Canada"; country[2] = "France"; country[3] = "Germany"; country[4] = "Switzerland"; return country; var villages = new Array(2); villages[0] = "Austria:Seefield 850m*"; villages[1] = "Austria:Ellam 100m"; return villages; } function snowReport(countryIndex){ var string = ""; for (var i = 0; i < countryIndex.length; i++){ str += countryIndex[i] + " "; } return str; } </script> </head> <body> <script> var x = makeArray(); document.write(snowReport(x)); </script> </body> </html> Many thanks! I think this is a pretty easy to fix error made by a newb ( me. Can anyone tell me why the call to "this.slideNext() " in the code below does not work. Apparently "this.slideNext() " is not a function? Code: function ScoopAnimation(_path, _start, _end, _delay){ this.start = _start this.end = _end; this.delay = _delay; this.path = _path this.currentFrame = _start; this.slideNext() = function (){ this.currentFrame ++; console.log(' next this.currentFrame : ' +this.currentFrame ); } this.start= function () { console.log('next this.start() : ' +this.currentFrame ); //THE NEXT LINE CAUSES THE ERROR! this.slideNext() } this.start(); } So erm. Hello there. I fail at javascript, and yet, I'm trying it. Anyways, I'm working on this thing. It's an extension for google chrome very similar to firefox plugins and so on. I'm making an extension so that, when installed, it changes the look of facebook completely. I have successfully changed the colors. However, I am having some trouble getting my javascript to change images. If anybody out there has some insight on what I'm doing wrong, I am glad to accept any kind of help that anyone is willing to give me, lol. What I've done so far: I have to change the facebook logo (what I'm trying to do now) and then change the links, and very few more things, and I'm done. Problem: I can't figure out how to change the image. I can change the background color, as you saw earlier. I just need a code to change the image. The CSS behind it is: Code: #pageLogo a{background:#3b5998 url(/rsrc.php/z8S5R/hash/ez3x5cuc.png) no-repeat -21px 0;display:block;position:absolute;height:31px;left:-6px;width:103px;top:10px} and the HTML implementing it is: Code: <h1 id="pageLogo"><a href="http://www.facebook.com/?ref=logo" title="Home" accesskey="1"></a></h1> and my structure of javascript is: Code: for(i=0;i<=document.getElementsByTagName("div").length;i++) { if(document.getElementsByTagName("div")[i].id != null) { if((document.getElementsByTagName("div")[i].id=="blueBar")) { document.getElementsByTagName("div")[i].style.backgroundColor='#B22222'; } if(( document.getElementsByTagName("div")[i].id == "headNavOut")) { document.getElementsByTagName("div")[i].style.backgroundColor='#8B0000'; } } } }); I appreciate any help anyone's willing to give. I was going through an article on JavaScript objects on "http://www.howtocreate.co.uk/tutorials/javascript/javascriptobject" and there I read Quote: Intrinsic objects - variable types with constructors. * Array * Boolean * Date * Function * Image * Number * Object * Option * Regular Expression * String does it mean that, whenever I want to use any of these objects, I have to create it using new and only then I can use its properties or methods ? 1) There are other objects like document, history, location, navigator, parent and screen. If objects which need to be created using constructor are called intrinsic objects , then what are other objects which can be used without constructor are called as ? Array, Boolean, Image, Date etc all start with capital letter. While document, history, navigator etc start with lower case letter. Why is that ? Is there any difference between objects that start with upper case and those start with lower case ? Are they known by different names ? Thanks I have done a basic while loop code but I can not figure out how to make the output print in 4 lines containing 5 numbers each. Can anyone tell me how to specify the number of output that appears on each line? Code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>example</title> </head> <body> <script type="text/javascript"> <!-- var x = 1; var linebreak="<br/>" while (x <= 20) { document.writeln("" + x + " " + ""); x = x + 1; } // --> </script> </body> </html> Hello All, I have a rather complex (well, to me at least, it's complex ) "loop" (not in a programming way, but in a metaphorical way) that I need to close, and, considering that a lot of Javascript (as well as some .php) is involved, I was hoping I could get some help here. My project involves a form that pulls data from an xml file, and then has the user check radio buttons on whether they approve of the information pulled from the xml file. The user then submits the form (that includes their email address), then, a pdf file of the form information, including the xml data AND the radio button and text data, is automatically generated and emailed to the user. The form-to-pdf software I'm using is found at this link: http://coreyworrell.com/blog/article...pdf-attachment the Demo is he http://coreyworrell.com/demos/pdf_email/form.php (Excellent software, by the way. A html form that, upon submission, dynamically creates a pdf file of the form, and then automatically emails that file to whomever you want, including the user? Tooooo cool.) I've set up a sample, below, for what the entire loop needs to do. The first file is the "test.xml" file that includes the sample data: Code: <?xml version="1.0" encoding="UTF-8"?> <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Quotediscrepancy.xsd" generated="2011-01-14T11:03:31"> <XMLtest> <Name>Bob Jones</Name> <Address>123 4th Street</Address> </XMLtest> </dataroot> The second file is the form itself -- sample_form.php -- that pulls the data from the test.xml file, AND includes form elements like radio buttons and text fields: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <HEAD> </HEAD> <body> <form action="pdf.php" method="post"> <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","test.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1' cellpadding='5'>"); document.write("<tr><td> <b>Customer</b>"); document.write("</td><td> <b>Address </b>"); document.write("</td></tr>"); var x=xmlDoc.getElementsByTagName("XMLtest"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("Address")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> <br><br> Email: <input type="text" name="email"> <br><br> Yes: <input type="radio" name="radio1" value="Yes"> :: No: <input type="radio" name="radio1" value="No"> <br><br> <p><button type="submit">Click Here to Submit Order</button></p> </form> </body> </html> Here's where I'm stuck. I don't know how to send all of the xml data AND the form data to the next step in the "loop" -- where the pdf file is dynamically created -- a version of the file "pdf.php" in the above-mentioned softwa Code: <html> <head> <style> body {font-family:Helvetica, Arial, sans-serif; font-size:10pt;} table {width:100%; border-collapse:collapse; border:1px solid #CCC;} td {padding:5px; border:1px solid #CCC; border-width:1px 0;} </style> </head> <body> <h1>Form Results</h1> <table> <tr> <td>Name:</td> <td><?php echo $post->name; ?></td> <td>Address:</td> <td><?php echo $post->address; ?></td> <td>Email:</td> <td><?php echo $post->email; ?></td> </tr> <tr> <td>Yes:</td> <td colspan="3"><?php echo $post->yes; ?></td> </tr> <tr> <td>No:</td> <td colspan="3"><?php echo $post->no; ?></td> </tr> </table> </body> </html> Any ideas? MUCH thanks. I have a general javascript question. It may apply in this forum but maybe in the asp forum. I have a java applet on a site that I am building. If someone visiting the site doesn't have their javascript turned on, and chooses not to, is there some line of code that I can use that will detect that and replace the applet for an image I create? The site is developed in asp, but being that it is a javascript question, I thought it may apply here. Gary Hi. This is my first post, so please bear with me!. I am writing some Javascript for some InDesign automation (shouldn't matter what for, but some background info). I have up to now been resorting to passing a script to Applescript, which then passed a shell command (via do script) to Terminal. This works, but is limiting my script to Mac only. I recently found I can open a socket, and send the PHP page my variables without leaving JavaScript.. Here is the code I am using with the Applescript combo: function combinedErrorReport(errorText) //errorText is something like "Library not found" { myServerAddress = "http://automation.yappp.net/"; errorText = encodeURI(errorText); myFullScriptString = "do shell script \"curl -0 "+ myServerAddress + "sendSrcError.php?e=" + errorText + "\""; myForceError = app.doScript(myFullScriptString, ScriptLanguage.APPLESCRIPT_LANGUAGE); } and this is what I want to use using a javascript socket... function combinedErrorReportWithSocket(errorText) //errorText is something like "Library not found" { myServerAddress = "automation.yappp.net:80"; errorText = encodeURI(errorText); conn = new Socket(); conn.open(myServerAddress); conn.write("GET /sendSrcError.php?e=" + errorText+"\ HTTP/1.0\n\n"); reply = conn.read(999999); conn.close; } The socket option simply does nothing. It opens the connection, but doesn't pass anything to the PHP. Anyone have any ideas? Cheers Roy Hey guys, I've got a question about this array in my code. I have my array at a size of 20 and all of the elements are initialized to 5. What i want to do is when the user types in the word "dog" i want to increase one of the first 10 elements in my array by 1, increasing it from 5 to 6. How would you do such a thing?
Hi I am developing a timer kind of thing here is my requirement: I have a form which retrieves results from DB. and the form has 2 buttons startcount, stop count with a textbox already filled with time in seconds data from DB.(let us say the text box holds 600 as of now). when the user clicks start count it should start the counting from 601,602,,,goes on until user hits stop button. How can i acheive this...here is my code so far... Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> var t; var timer_is_on=0; function timedCount(TestVar) { TestVar =TestVar+1; //document.getElementById('txt').value=c; alert("you typed:"+TestVar); //c=c+1; t=setTimeout("timedCount()",1000); } function doTimer(form) { TestVar = parseInt(form.txt.value); //alert("you typed: " +TestVar); timedCount(TestVar); } function stopCount() { clearTimeout(t); timer_is_on=0; } </script> </head> <body> <form name="test" onsubmit="timedCount()" > <table width="200" border="0"> <tr> <th scope="row"><label> <input type="button" value="Start count!" onclick="doTimer(this.form)" /> </label></th> <td><label> <input type="text" name ="txt" id="txt"/> </label></td> <td><label> <input type="button" name="stop" id="stop" value="Stop" onclick="stopCount(this.form)" /> </label></td> </tr> </table> </form> </body> </html> Thanks in adv.... Hi Peers, I am capturing query data into different Javascript arrays and that is the only way i have for now...anyway ..i have what i want in JS arrrays > is there a war to perform CRUD operations on those arrays : my Arrays look like this : A1 : EmpID / A2 : Name / A3: Fistanme.. A1[0] : 1 / A1[0] : Paul /A1[0] : Newman A1[1] : 2 / A1[1] : Paul /A1[1] : Simon i want to be able to display the information like and give the ability to create , update or delete the record based on the EmpID unique number: EmpID / Name / Firstname 1 Paul Newman Update ( hyperlink) - Delete ( hyperlink) 2 Paul Simon Update ( hyperlink) - Delete ( hyperlink) i am using Coldfusion CF 7 and i was told since i want to keep the data into JS array that the only way to do it is usinig JAvascript any thoughts how can this be done./??? Thanks Hello guys, Im new to Javascript,please help me ya in my php code, I retrieve a ID value and assign to variable like below PHP Code: $id = $gettingdata['id']; and I want this id to be include together with javascript "insertsubcat" function like below Code: <a href="javascript:insertsubcat('.$ID.');"/>Click to insert this data</a> in the javascript page, I dont know how to call back the id value and i try like code below but it doesnt work Code: function insertsubcat(data) { var data = data.value; . . . . } Any idea? Thanks Azhan Malaysia Hi, Any help would be greatly appreciated. Below is the javascript that I am having a problem with. The two id's in question are at the end of the javascript. fyi Its for a form. What will happen is that the user selects the first dropdown with an id of 00N20000001HjsR. They then selects another dropdown with an id of 00N20000001Hp9Q. What I want is that on the second dropdown, if the user selects the value of Beauty Therapy, it will change the value of the first dropdown (id 00N20000001HjsR) to 'ANCB'. The problem I have at the moment is that it is not overriding the original dropdown selection. Any ideas on how to solve this? Much appreciated in advance, thanks!!! Code: <script type="text/javascript"> //check if prospectus is on document.formRec.onsubmit = function() { return ValidForm(); }; function ValidForm(){ if (document.getElementById("first_name").value == ""){ alert("Please enter your first name"); document.getElementById("first_name").focus(); return false; } if (document.getElementById("last_name").value == ""){ alert("Please enter you last name"); document.getElementById("last_name").focus(); return false; } if (document.getElementById("email").value == ""){ alert("Please enter your email address"); document.getElementById("email").focus(); return false; } if (document.getElementById("phone").value == ""){ alert("Please enter your contact number"); document.getElementById("phone").focus(); return false; } if (document.getElementById('00N20000001Hp9a').value== "--None--"){ alert("Please choose you country of citizenship"); document.getElementById('00N20000001Hp9a').focus(); return false; } if (document.getElementById('00N20000001HjsR').value== "--None--"){ alert("Please select type of study you are interested in"); document.getElementById('00N20000001HjsR').focus(); return false; } switch (document.getElementById('00N20000001Hp9Q').value) { case "--None--": alert("Please select area of study you are interested in"); document.getElementById('00N20000001Hp9Q').focus(); return false; break; case "Beauty Therapy": document.getElementById('00N20000001Hp9Q').value = "Beauty Therapy"; document.getElementById('00N20000001HjsR').value = "ANCB"; break; } return true; } </script> |