Hi,
I've found a script that works as a timer and was wondering if someone could give me a hand changing it a little. The problem is that if you click the start button and it counts up to 10 then you push the stop button that works fine. However if you push the start button again instead of continuing from 10 it goes back to 0 then starts again.
Thanks very much
Ed
<script language="JavaScript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas -
var timerID = 0;
var tStart = null;
function UpdateTimer() {
if(timerID) {
clearTimeout(timerID);
clockID = 0;
}
if(!tStart)
tStart = new Date();
var tDate = new Date();
var tDiff = tDate.getTime() - tStart.getTime();
tDate.setTime(tDiff);
document.theTimer.theTime.value = ""
+ tDate.getMinutes() + ":"
+ tDate.getSeconds();
timerID = setTimeout("UpdateTimer()", 1000);
}
function Start() {
tStart = new Date();
document.theTimer.theTime.value = "00:00";
timerID = setTimeout("UpdateTimer()", 1000);
}
function Stop() {
if(timerID) {
clearTimeout(timerID);
timerID = 0;
}
tStart = null;
}
function Reset() {
tStart = null;
document.theTimer.theTime.value = "00:00";
}
//-->
</script>
<body onload="Reset()" onunload="Stop()">
<center><form name="theTimer"><table>
<tr>
<td colspan=3 align=center>
<input type=text name="theTime" size=5>
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<input type=button name="start" value="Start" onclick="Start()">
</td>
<td>
<input type=button name="stop" value="Stop" onclick="Stop()">
</td>
<td>
<input type=button name="reset" value="Reset" onclick="Reset()">
</td>
</tr>
</table></form></center>
I've found a script that works as a timer and was wondering if someone could give me a hand changing it a little. The problem is that if you click the start button and it counts up to 10 then you push the stop button that works fine. However if you push the start button again instead of continuing from 10 it goes back to 0 then starts again.
Thanks very much
Ed
<script language="JavaScript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas -
var timerID = 0;
var tStart = null;
function UpdateTimer() {
if(timerID) {
clearTimeout(timerID);
clockID = 0;
}
if(!tStart)
tStart = new Date();
var tDate = new Date();
var tDiff = tDate.getTime() - tStart.getTime();
tDate.setTime(tDiff);
document.theTimer.theTime.value = ""
+ tDate.getMinutes() + ":"
+ tDate.getSeconds();
timerID = setTimeout("UpdateTimer()", 1000);
}
function Start() {
tStart = new Date();
document.theTimer.theTime.value = "00:00";
timerID = setTimeout("UpdateTimer()", 1000);
}
function Stop() {
if(timerID) {
clearTimeout(timerID);
timerID = 0;
}
tStart = null;
}
function Reset() {
tStart = null;
document.theTimer.theTime.value = "00:00";
}
//-->
</script>
<body onload="Reset()" onunload="Stop()">
<center><form name="theTimer"><table>
<tr>
<td colspan=3 align=center>
<input type=text name="theTime" size=5>
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<input type=button name="start" value="Start" onclick="Start()">
</td>
<td>
<input type=button name="stop" value="Stop" onclick="Stop()">
</td>
<td>
<input type=button name="reset" value="Reset" onclick="Reset()">
</td>
</tr>
</table></form></center>