<html>
<head>
<script language="JavaScript">
var c1 = 0;
var c2 = 0;
var c3 = 0;
var o1 = 0;
var o2 = 0;
var o3 = 0;
ID = window.setTimeout("start();", 100);
function start() {
if (c1 == 59) {
c1 = 00;;
if (c2 == 59) {
c2 = 00;
}
else c2++;
}
else c1++;
if (c1 == 0 || c1 == 1 || c1 == 2 || c1 == 3 || c1 == 4 || c1 == 5 || c1 == 6 || c1 == 7 || c1 == 8 || c1 == 9) o1 = "0" + c1;
else o1 = c1;
if (c2 == 0 || c2 == 1 || c2 == 2 || c2 == 3 || c2 == 4 || c2 == 5 || c2 == 6 || c2 == 7 || c2 == 8 || c2 == 9) o2 = "0" + c2;
else o2 = c2;
if (c3 == 0 || c3 == 1 || c3 == 2 || c3 == 3 || c3 == 4 || c3 == 5 || c3 == 6 || c3 == 7 || c3 == 8 || c3 == 9) o3 = "0" + c3;
else o3 = c3;
document.forms[0].elements[0].value = o3 + ":" + o2 + ":" + o1;
ID = window.setTimeout("start();", 100);
}
</script>
</head>
<body>
<form name="frm1">
<input type="text" name="timer1">
<input type="button" name="but1" value="start" onClick="c1=0; c2=0; c3=0; o1=0; o2=0;
o3=0; start();">
<input type=button name="but2" value="stop" onClick="window.clearTimeout(ID);">
</form>
</body>
</html>
Status Bar gives the error: Object doesn’t support this action.
You get the error in Internet Explorer because there is already a variable
startin use, either by the browser itself, or by jsFiddle. After you have used it to define the function, it’s for some reason changed into a variable containing the string"fileopen".If you rename the function
startto something else, it works:http://jsfiddle.net/Guffa/yqsmy/
Anyhow, you should rather use an interval instead of a timeout for this:
Javascript:
HTML:
Demo: http://jsfiddle.net/Guffa/B4a54/7/
If you want the timer to be exact, you should save the start time in a variable, then subtract that from the current time to get the elapsed time, and only use the interval to display the elapsed time.