Countdown Timer Question

J

Janwillem Borleffs

Papajo said:
This timer counts down from 5 and stops at 0, is there anyway to loop
it so it will start the count down again? plus could the amount of
times it loops be set?
Thank you, Joe

var iCountStart = 5;
var loopCountStart = 3;
var iCount;
var loopCount;
var to;

function startCountdown(start) {
if (start) {
if (to) {
clearTimeout(to);
}
loopCount = loopCountStart;
iCount = iCountStart;
}
if (loopCount > 0) {
window.status = " "+iCount+" ";
if (--iCount < 0) {
loopCount--;
iCount = iCountStart;
}
to = setTimeout('startCountdown(false)', 1000);
}
}


<input type="button" onClick="startCountdown(true)" value="Start">


JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top