Jump to content

setInterval Function


guleriahp

Recommended Posts

I am using setInterval() function like this.fun2(){ return setInterval();}fun(){ interval = fun2(); -----some code------ ------some code-----}The problem is that when fun2() is called it is executing the fun2()... but by the side ----some code---- is also executed. what i want is, this '---some code--' must be executed only after execution of fun2() is over. plz suggest how can do that?

Link to comment
Share on other sites

guleriahp,You can set a global variable and check it's state to execute your next code.

<html><head>  <title></title><script type="text/javascript">var go_next = false;//variable for our check cyclevar tm = null;function checkCond(){var form = document.forms["f"];  if(form.elements["e1"].value.toLowerCase() == 'go'){     // next line clears the check cycle     clearInterval(tm);     go_next = true;     doForm(form);       }}function init(){tm = setInterval('checkCond()', 800);setTimeout('ckNext()', 1000);}function ckNext(){ if(go_next){   alert('Everything is complete..');   } else {   setTimeout('ckNext()', 1000);   }}function doForm(form){ form.elements["e2"].value = 'OK';}window.onload = init;</script>  </head><body><form name="f"> Go to start: <input type="text" name="e1"><br> Result: <input type="text" name="e2"></form></script></body></html>

Get back to us if you have any questions.Thanks,

Link to comment
Share on other sites

thanx hacknsack, i'll try that.

guleriahp,You can set a global variable and check it's state to execute your next code.
<html><head>  <title></title><script type="text/javascript">var go_next = false;//variable for our check cyclevar tm = null;function checkCond(){var form = document.forms["f"];  if(form.elements["e1"].value.toLowerCase() == 'go'){     // next line clears the check cycle     clearInterval(tm);     go_next = true;     doForm(form);       }}function init(){tm = setInterval('checkCond()', 800);setTimeout('ckNext()', 1000);}function ckNext(){ if(go_next){   alert('Everything is complete..');   } else {   setTimeout('ckNext()', 1000);   }}function doForm(form){ form.elements["e2"].value = 'OK';}window.onload = init;</script>  </head><body><form name="f"> Go to start: <input type="text" name="e1"><br> Result: <input type="text" name="e2"></form></script></body></html>

Get back to us if you have any questions.Thanks,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...