2

I'm trying to make a progress bar that moves each 5 seconds. Here is my code:

function Progress(runner, validlinks)
{
 if (runner <= validlinks)
 {
 var myString = document.getElementById('links').value;
 var mySplit = myString.split("\n");
 var ValidLinksCount = 0;
 for(i = 0; i < mySplit.length; i++)
 {
 if (mySplit[i].search("who") != -1)
 ValidLinksCount++;
 ValidLinksCount++;
 else if (mySplit[i].search("we") != -1)
 ValidLinksCount++;
 }
 var jump = Math.ceil(100 / ValidLinksCount);
 runner++;
 document.getElementById("progressDiv").style.width = parseInt(document.getElementById("progressDiv").style.width) + jump + "%";
 window.setTimeout(Progress(runner,ValidLinksCount), 5000);
 }
}

I call it on button submit like this:

<input type="submit" name="submit" disabled="true" onclick="Progress(0,0);" value="check" />

It just runs and doesn't wait 5 seconds until next run, why? Thanks.

asked Dec 18, 2011 at 15:31

1 Answer 1

7

Pass, don't call, a function.

window.setTimeout(function() {
 Progress(runner,ValidLinksCount);
}, 5000);
answered Dec 18, 2011 at 15:33
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thank you so much, I've been busting my head to find the solution.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.