timer function

D

Darren Showers

I'm running a timer function that counts down from set time frames. It has
an odd tendency to drop 2 seconds at the beginning but then work fine the
rest of the way. Can anyone suggest what could be happening here?
 
E

Evertjan.

Darren Showers wrote on 09 nov 2004 in
microsoft.public.scripting.jscript:
I'm running a timer function that counts down from set time frames.
It has an odd tendency to drop 2 seconds at the beginning but then
work fine the rest of the way. Can anyone suggest what could be
happening here?

What is happening here is that you don't show us the code.
 
D

Darren Showers

Thank you for the unnecessary candor. Here is the code:

function startTimer() {
running = true;
var now = new Date();
start =now.getTime();
var seconds = getSec();
var setTime = 1000 * seconds;
endTime = start + setTime;
showCountDown()
}

function getSec() {
var r = document.frm.radio1;
for (var i=0; i<r.length; i++) {
if (!r.checked) continue;
else return r.value;
}
return null;
}

function showCountDown() {
var present = new Date();
moment = present.getTime();
if (endTime - moment<= 0) {
stopTimer();
displayTimer.innerHTML = "TIME'S UP!";
showTimeOver();
} else {
var lapse = new Date(moment - start);
var minLapse = lapse.getMinutes();
var secLapse = lapse.getSeconds() + 1;
var timeLapse = minLapse;
timeLapse += ((secLapse < 10) ? ":0" : ":") + secLapse;
document.frm.timeLapse.value = timeLapse;
var delta = new Date(endTime - moment);
var theMin = delta.getMinutes();
var theSec = delta.getSeconds();
theTime = theMin;
theTime += ((theSec < 10) ? ":0" : ":") + theSec;
document.frm.timerDisplay.value = theTime;
displayTimer.innerHTML = theTime;

if (running) {
timerID = setTimeout("showCountDown()",1000)
}
}
}

function stopTimer() {
displayTimer.innerHTML = theTime + " TIMER STOPPED";
clearTimeout(timerID);
running = false;
}
 

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

timer function 0
timer function 0
Javascript problem - "crash browser" "infinite loop" timer 1
Timer 1
Timer 1
Web Service (or Timer) Randomly Ending 0
Help calling a function 3
timer for a function 2

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top