JavaScript - Order And Timing Of Execution
Hi,
I have a javascript function that is formatting data before it is being passed along to an Ajax call. The same function is formatting data for two variables but it seems as though the first call to the is being preempted by the same function call for the second variable's data formatting. On top of that the function does not seem to finish execution by the time it reaches the Ajax call so none of the data seems to be passed along. Here's a condensed version at what I'm dealing with: Code: var data_group1 = FormatData('type_1'); var data_group2 = FormatData('type_2'); Ajax(data_group1, data_group2); How can I ensure that the first call to FormatData is finished before the next call to it begins. Additional how can I prevent the Ajax function from executing until the first two lines have executed. Thanks a ton. Similar TutorialsIs there a way to have functions execute sequentially, rather than additively, using setTimeout? The problem here is varying browser speeds. Say we have some functions and they're set to fire after certain intervals, to create a rhythm. If you set them this way: Code: fn1(); setTimeout('fn2()',3000); setTimeout('fn3()',5000); and fn2() takes approx 1600ms to complete, there should be a 400ms pause before fn3(). But no two browsers are the same: the rhythm is at the mercy of browser speed. In some browsers, fn3() will fire before fn2 is finished. It sounds finicky, but it's like looking at a cut in a film: it's either smooth and not noticed, or it jars. Is there a way to execute which says: "do fn1(); when it's finished, wait 3 seconds and do fn2(); when it's finished, wait 400ms and do fn3()" ? cheers. Hi, i'm not a Javascript programmer but have adapted this slideshow from an open source online and i need some help in adding some touches and finishing it off. www.sixtydegreedays.com I want to add timings to the main images so they scroll through at a set interval, as well as being able to be clicked through as they are now, can someone help with this? Also, i cannot figure out where the first image (horsebox) goes once i have clicked through the other links - if i click back to horsebox, the image disappears! These are the two most important things, but it would also be helpful if someone could help me pre-load the images to cut down on load time. Hopefully these are quick fixes and someone can take the time to help. Cheers Hello everyone, I tried to create javascript float menu and this my code: 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div id="static" style="width:150px; height:150px; position: absolute; border:1px solid yellow; right: 5px;">HELLO</div> <script type="text/javascript"> setInterval("document.getElementById('static').style.top=document.body.scrollTop+25+'px' ",1000).setTimeout(100); </script> <br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br />' text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> text-here text-here text-here text-here text-here<br /><br /><br /> </body> </html> but the results it's not good like: http://www.jtricks.com/javascript/na.../floating.html what's the lack or mistake of my script? please help me thank you Hello, hoping someone can help. Have built a slide show for header using following, but there is a very annoying time lag between the photo changing and the caption changing (ie photo changes, then a brief moment later the caption changes). Can anyone tell me how to correct this so that the caption and the photo change simultaneously? Thanks in advance! <script type="text/javascript"> $(function() { $('#slideshow').cycle({ fx: 'fade', timeout: 3000, after: function() { $('#caption').html(this.alt); } }); }); </script> Hello guys, I'm new to Javascript and my question involves text appearing upon a button click or after a set time. I have the following code: Code: <script type="text/javascript"> function timedMsg() { document.write("Timed Messege."); } And the button: Code: <form> <input type="button" value="Display timed alertbox!" onClick="timedMsg()" /> </form>[ I guess document.write is not the correct command to use in such situations, since it just replaces the whole page. Which command should I use so that the wanted text appears within the page, without reloading or replacing it? Thanks in advance. I could not find a proper command in my search. it is my understanding that all lines of code are executed in a "top down" order. (exception: temporary exit/return on functions), even then, when return from function, top down continues on its way. simple enough. so why is this set of instructions jumping forward several lines of code and jumping back to continue execution? Code: 202. var statusIndex=0; 203. $('#cpqcSelect').click( function() { 204. alert('line 204: statusIndex ='+statusIndex); 205. $(this).css({'background-color':'#f00','border':'3px solid #000','color':'#000'}); 206. alert('line 206'); 207. $.get('getRangeStatus-server-script.php', {data:0}, processResponse ); 208. alert('line 208'); 209. function processResponse(data,status){ 210. if (status == 'success') { statusIndex = data } 211. else { statusIndex = 'error' } 212. alert('line 212; value of statusIndex = '+statusIndex); 213. }; // end function processResponse(data,status) 214. alert('line214'); 215. return false; // stop the link from reloading the page or traveling elsewhere 216. }); //end $('#cpqcSelect').click( function() i'm using the alert() boxes to track how this code is being executed. oddly enough it does not go top down as i think it should. maybe something is forcing it to jump around? i don't know? line 204 fires. ok. line 206 fires. ok. line 208 fires. ok. but then execution jumps into line 214, before it goes into the function on line 209. thats odd? execution goes thru the function and spits out line 212 correctly. then it jumps to line 215. why the jump to line 214 before it goes into the function? i need execution to complete the function at 212 first and then go on. but it doesn't want to do that. possible error causing odd jumping around? would appreciate your eyes, please. thanks, Paul How to know the execution time of a function? For example, which of these functions run in less time? That is, which of these functions are more weightless to run? Code: document.getElementById("my_image").src = "images/picture.png"; //or document.getElementById("my_image").style.webkitTransform = "rotate(45deg)"; Thanks in advance! I have code that I have written to clean up the value of a text box before submitting it to a database, the problem I have is that if the value is blank, I want to throw up an alert and halt the JS from continuing, normally I would put in a return false statement and be done, but since the function is already returning a value I was wondering if there was another way to stop code execution. So if cleanString is not blank after it processes code should continue, if it is blank it should stop everything after the alert message. I know I can code for it on the calling side but I was hoping to include it all in one function. If I return false after the alert the output box actually says false and code continues to process. Code: <script> function cleanString(myString){ //Removes All Special Characters and Double Spaces and trims the text temp = myString.replace(/[^a-zA-Z 0-9]+/g,'') temp = temp.replace(/^\s+|\s+$/g, ''); temp = temp.replace(/\s+/g, ' '); if(temp == ""){ alert('Input string cannot be blank, or contain special characters.'); //Halt Code execution here } else { return temp; } } function testan(i){ document.getElementById('output').value = cleanString(i); alert("still going"); } </script> Input: <input type="text" id="input" style="width: 500px;" value=" Test (Parens) [brackets] 1234 2 4 ,Comma "Quote "/><br /> Output: <input type="text" id="output" style="width: 500px;" /><br /> <input type="button" value="Go" onclick="testan(document.getElementById('input').value);" /> Say that I've got the following XML Code: <document> <block key="block1"> <p>This is a <bold>paragraph</bold></p> </block> <block key="block2"> <p>Additional paragraph</p> </block> </document> Obviously the schematics of this data and the constraints placed upon them can be described using XSD. For example, the following rules would apply: * must be a document element as the top-level parent element * must be at least one block element as a child of document * each block must have a unique key value * blocks can have 1...n p child elements. * p elements can have 0...n bold child elements What I'm looking for is an engine that executes on the client-side (JavaScript / jQuery) that can parse the XSD and flag any errors. In addition I would also need to be able to interrogate the engine in order to determine what are valid child nodes at a particular level of the XML. For example, the following types of queries might be asked of the engine: * Q: Is the overall XML valid? A: yes / no + report * Q: I'm looking at the element block (key="block2"). What are the valid child elements of this element? A: p (1...n). * Q: I'm looking at the element p in the first block (key="block1"). What are the valid child elements of this element? A: #text, bold (0...n). Determining the valid child elements of a particular element is something akin to how Visual Studio e.g. 2010 uses Intellisense. For example, given a schema Visual Studio let's you know what the valid elements are at a particular position as you type enter the XML. Finally I've mentioned XSD / XML above but we do not necessarily have to be constrained to these technologies so alternative ideas will be appreciated equally as well. Thank you for taking the time to examine my post. Hi, I have a function that I'm trying to modify. It adds an element to the page. The problem is, I require that ClickGeocode() finishes executing before the rest of the code in the function completes. Currently that is not the case... Any ideas? Code: Event.add(window, 'load', function() { Event.add('addressSearch', 'click', function() { ClickGeocode(); var el = document.createElement('p'); el.innerHTML = " " + addressSearchAddress + " : [" + addressSearchRadius + "]"; Dom.add(el, 'AddressesVisited'); Event.add(el, 'click', function(e) { Dom.remove(this); }); }); }); Without elaboration plz see my code: Code: <body> <script> var b="s"; </script> <button target="_blank" onclick="window.open('http://......php?b="javascript:document.write(b);"&id=2&q=<?php print $_GET['q']; ?>','1','');return false;">xyz</button> </body> i don understand why this javascript:document.write(b); doesnt work in url... i know its simple yet it make my hair out of my head. plz count it.. I have discovered a XSS vuln in a website and I'd like to use this as a cookie grabber. If you can help, <removed>.
I am developing a web page which contains a java script file. Java script file is created using excel tool. My problem is that the execution time of a java script function is very high,mainly in chrome browser. what will be solution to overcome this?
Hello guys, please help me in building an order form, the details. The order form consist of text box product quantity, unit price, total price, sub total price, tax, discount, grand total quantity and grand total price. There are 8 products so there will be 8 product quantity, unit price, total price text boxes. When a user enter the product quantity and unit price, the total price column should be automatically calculated e.g. if product quantity is 8, unit price is 2 then the total price should come to 16. The sub total price will be automatically calculated which should be the addition of all total prices so as the product quantity. The user will enter the tax and discount amount which should be calculated as percentage. Tax will be added to sub total and discount will be subtracted from sub total and then the total price will be displayed in the grand total text box. Please help me to develop this form. Thank You I have a challenge I gave to myself. I want a script that asks me to put things in order. Say I want a quiz of family, order of age. I have a table with the left cell everybody's name I want a script where I click on a name and it moves over to the right hand cell, up top, then the next clicked named is put under it and so on until all the names are moved over. So far I have this, but I know there is a lot of room for improvment. any suggestions? <HTML> <HEAD> <TITLE>Put Bible books in proper order</TITLE> </head> <body> <h1>Hello World!</h1> <TABLE BORDER=5><TR><TD> <FORM NAME="BOOKS"> <script language="javascript" type="text/javascript"> alert('This is what an alert message looks like.'); FUNCTION TESTER() { ALERT('WORKS'); VAR GOOD=0; VAR BAD=0; if (BOOKS.FONE="A") { GOOD++; } ELSE { BAD++; }; ALERT("YOU HAVE INCORRECT"); } </script> <TABLE BORDER=0><TR><TD> <TABLE BORDER=1> <TR><TD><INPUT TYPE="BUTTON" VALUE="Adam" NAME="GONE" onClick="javascript:TEMP.value=this.value";> <TR><TD><INPUT TYPE="BUTTON" VALUE="Dave" NAME="GTWO" ONCLICK="javascript:TEMP.value=this.value";> <TR><TD><INPUT TYPE="BUTTON" VALUE="Kile" NAME="GTHREE" ONCLICK="javascript:TEMP.value=this.value";> <TR><TD><INPUT TYPE="BUTTON" VALUE="John" NAME="GFOUR" ONCLICK="javascript:TEMP.value=this.value;"> <TR><TD><INPUT TYPE="BUTTON" VALUE="Geroge" NAME="GTWO" ONCLICK="javascript:TEMP.value=this.value;"> </TABLE> <TD VALIGN="CENTER" ALIGN="CENTER" WIDTH=30> <INPUT TYPE="BUTTON" VALUE=" " NAME="TEMP"> <TD> <TABLE BORDER=1> <TR><TD><INPUT TYPE="BUTTON" VALUE="?????" NAME="FONE" ONCLICK="javascript:this.value=TEMP.value;TEMP.value=' '"> <TR><TD><INPUT TYPE="BUTTON" VALUE="?????" NAME="FTWO" ONCLICK="javascript:this.value=TEMP.value;"> <TR><TD><INPUT TYPE="BUTTON" VALUE="?????" NAME="FTHREE" ONCLICK="javascript:this.value=TEMP.value;"> <TR><TD><INPUT TYPE="BUTTON" VALUE="?????" NAME="FFOUR" ONCLICK="javascript:this.value=TEMP.value;"> <TR><TD><INPUT TYPE="BUTTON" VALUE="?????" NAME="FFIVE" ONCLICK="javascript:this.value=TEMP.value;"> </TABLE> </TABLE> <INPUT TYPE="BUTTON" NAME="CHECK" onClick="JAVASCRIPT:ALERT()" VALUE="CORRECT???"> </FORM> </TABLE> </BODY> </HTML> Hi their, i'm trying to create an online order page i'm having probelms calculating totals from the options not sure if i've designed it correctly i have 3 select options (with 4 different products in each) a single checkbox for another single product and a final select tag for amounts (500/1000/2500/5000) i need to assign each select option a value then * it by the amount select am i best using onchange/an array or ditching select tags for something easier any help greatly appreciated Marty hi, This is my proble, I have some controls(textbox's,dropdown's),and using javascript,tab order,when i press "Enter" key the tab order 1 is not working(The cursor is focussed in the control which is tab order is 1, not moved to tab order 2) please give a solution. NARASIMHA RAO K. I am using the following code to rotate my banner 3 times. I am trying to get it to order. Ive set it up so that you can choose yes/no drop down as to whether you wnat a panel to show and I have also set it up with a drop down so you can specify 1,2,3. I want to be able to randomly change the order to say 2, 1, 3 it dosent seem to work with what I have below. Any suggestions? Code: <script type="text/javascript"> $(document).ready(function(){ $("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true); $(".ui-tabs-panel > a").hover( function() { $("#featured").tabs("rotate",0,true); }, function() { $("#featured").tabs("rotate",5000,true); } ); <div id="featured" > --------------------------------------------------------- <% String sCount=""; String stitle = ""; String iPanels = ""; String sShowPanels = ""; String sContent=""; %> <ul class="ui-tabs-nav"> <% for(int i=1;i<7;i++){ sCount="" + i; stitle = "stitle"; stitle= stitle + i; iPanels = "iPanels"; iPanels = iPanels + i; sShowPanels = "sShowPanels"; sShowPanels = sShowPanels + i; //out.print(requestItem.getFieldValue(iPanels) + "=" + sCount); if(requestItem.getFieldValue(iPanels).equals(sCount)){ if(requestItem.getFieldValue(sShowPanels)!=null && requestItem.getFieldValue(sShowPanels).equals("Yes")){ if(requestItem.getFieldValue(stitle)!=null && requestItem.getFieldValue(stitle).length() >2){ %> <li class="ui-tabs-nav-item" id="nav-fragment-<%=i%>"><a href="#fragment-<%=i%>"> <%=requestItem.getFieldValue(stitle)%> </a></li> <% } } } } %> </ul> <% for(int i=1;i<7;i++){ sCount="" + i; stitle = "stitle"; stitle= stitle + i; iPanels = "iPanels"; iPanels = iPanels + i; sShowPanels = "sShowPanels"; sShowPanels = sShowPanels + i; sContent = "sContent"; sContent= sContent + i; if(requestItem.getFieldValue(iPanels).equals(sCount)) { if(requestItem.getFieldValue(sShowPanels)!=null && requestItem.getFieldValue(sShowPanels).equals("Yes")) { if(requestItem.getFieldValue(sContent)!=null && requestItem.getFieldValue(sContent).length() >2) { %> <div id="fragment-<%=i%>" class="ui-tabs-panel ui-tabs-hide" style=""> <%=requestItem.getFieldValue(sContent)%> </div> <% } } } } %> </div> </div> <!--content--> Hi, I need help with my javascript codes to finish my order form. The first problem I am encountering is this: I need the quantity to appear automatically in the total quantity for sub total. how is this? I have assigned TotalQuantity.value for the quantity. Thank you. You can see the image here. http://img821.imageshack.us/i/oderform.jpg/ i noticed the majority of the time when i practice coding javascript and run it, it never runs in the order i want it to. WHY?! like for example, if i want something to happen ONLY WHEN A BUTTON IS CLICKED, it would instead happen on page load :S its soooo frustrating heres one of my practice code which illustrates this problem. This code is suppose the stretch a div only wen it is clicked on. 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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div id="mybutton" style="height:50px; width:50px; background-color:#C00;"></div> </body> <script type="text/javascript"> var left = 0; var funct = function () { //alert("Thank you for clicking me"); left +=10; b.style.height = left + 'px'; if(left < 100) { var id = setTimeout(funct, 10); } } var b = document.getElementById("mybutton"); b.onclick = funct(); </script> </html> |