...

View Full Version : Timer: User at page



name _F1
09-02-2006, 04:11 PM
I'm trying to make a timer that displays how long a user has stayed at the page. I wish to display the time in the format hh:mm:ss.


function timeAtPage() {
if (started == 0) {
startingTime = new Date();
startingHour = startingTime.getHours();
startingMin = startingTime.getMinutes();
startingSec = startingTime.getSeconds();
started = 1;
}
currentTime = new Date();
currentHour = currentTime.getHours();
currentMin = currentTime.getMinutes();
currentSec = currentTime.getSeconds();
timeHour = currentHour - startingHour;
timeMin = currentMin - startingMin;
timeSec = currentSec - startingSec;
document.clockForm.timeatpage.value = timeHour+":"+timeMin+":"+timeSec;
clockTimer = setTimeout('timeAtPage()',1000);
}
This does not change the value of the text box at all. Is this the best way of displaying the time, and what is wrong with my code?

Any help would be greatly appreciated.

tpeck
09-02-2006, 04:57 PM
Don't know why your code doesn't work, but I use this code:

(if yours worked I would change to yours - it's much shorter!)

http://www.jdstiles.com/java/timer1.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum