...

View Full Version : Timer Question



Papajo
06-03-2009, 07:23 PM
Hi
This timer counts down from 15 seconds and stops, I want the timer to reset itself and start the countdown over again, indefinitely. Thanks Papajo





var refreshinterval=15
var displaycountdown="yes"

var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0

function starttime() {
starttime=new Date()
starttime=starttime.getTime()
countdown()
}

function countdown() {
nowtime= new Date()
nowtime=nowtime.getTime()
secondssinceloaded=(nowtime-starttime)/1000
reloadseconds=Math.round(refreshinterval-secondssinceloaded)
if (refreshinterval>=secondssinceloaded) {
var timer=setTimeout("countdown()",1000)
if (displaycountdown=="yes") {
document.form.show.value=""+reloadseconds+ "";
}}}


<form name="form">
<input type="text" name="show" size="3">
<input type='button' onClick='starttime()' value='Start'></form>

venegal
06-03-2009, 07:40 PM
It's as easy as calling starttime() again in an else statement at the very end.

It won't work of course, because you are overwriting that function with other stuff. Don't use the same names for functions and variables.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum