I have absolutely NO clue what you said you were trying to do, but your code works, it starts and stops with the functions. Here is code for it to alert on 15 secs, you can add another for 30 if you like, but if you want more help, please restate the question.
Code:
<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
if(c == 15){ alert("We have reached: " + c); }
t=setTimeout("timedCount()",1000);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onclick="doTimer()" />
<input type="text" id="txt" />
<input type="button" value="Stop count!" onclick="stopCount()" />
</form>
</body>
</html>
You're better off using setInterval. It works the same way as setTimeout, but executes continuously until you call clearInterval; removing the recursive function calling you have going on. I've taken the liberty of rewriting your code. It works as you described. If you want to alert a value counting the number of resets, just add some form of counter to the code.
Bookmarks