Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setInterval to slow a for loop

Status
Not open for further replies.

tkt

Programmer
Dec 13, 2001
7
0
0
US
I'm trying to set the speed that a FOR loop runs through. I'm dynamically submitting a form based on input from an array. The code works but only if it is slowed down (currently) with an alert line. If I could set an Interval I wouldn't have to keep pressing the alert box to close & could remove the code.

I can only get the setInterval to work with an array if I use an if statement and a counter in the function. But a document.form.submit() breaks the code in the middle of an interval.

Is there any way to slow down the for loop?

Any help?
 
here's an example of slowly looping through the elements of an array:

<script language=&quot;javascript&quot;>
var ar = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;];
var x = 0;

function doLoop() {
if (x < ar.length)
process();
}

function process() {
window.status = ar[x++];
setTimeout(&quot;doLoop();&quot;,1000);
}

// start the process
doLoop();



</script>
=========================================================
while (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top