I wrote this program. Its kinda of strange when I make a reset function reset(){c=0} its doest reset the setTimeout. However if I directly pass c=0 to the onclick button it does reset the timer. What is the logic of this?
Here is the program:
[HTML]<html>
<head>
<script type="text/javascript">
var c=0;
var t;
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}
function stopCount()
{
clearTimeout(t);
}
function reset()
{
c=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
//Problem Area---------------------------------------------------------------------
<input type="button" value="reset!" onClick="reset();">// if I pass "c=0" it works
//yet if I call the reset function which sets c=0 it doesnt work Why?
</form>
//-----------------------------------------------------------------------------------------------------
<p>
Click on the "Start count!" button above to start the timer. The input field will count forever, starting at 0. Click on the "Stop count!" button to stop the counting.
</p>
</body>
</html>[/HTML]