cubernya
Premium Member
Alright, I'm back again, and need some more help. This time I'm trying to code a very simple timer, not even a cubing timer (although I might make it one). I can't seem to get the timer to stop at all.
Source code:
As you can see, under stop(), I put the clear.interval. I've tried putting in window.clear.interval and/or window.int = ... but none have worked. I was just wondering how I should go about getting it to stop in Firefox. This is actually for a project, and I need a timer to show in the corner, but don't want something larger like qqTimer.
Source code:
Code:
<script type='text/javascript'>
function start(){
window.int = setInterval('timer()',10);
document.getElementById('startstop').onkeydown = 'stop()';
document.getElementById('startstop').value = 'STOP';
}
function stop(){
int = clearInterval(int);
document.getElementById('startstop').onkeydown = 'start()';
document.getElementById('startstop').value = 'START';
var t = document.getElementById('times').innerHTML;
var ct = document.getElementById('sec').innerHTML + document.getElementById('frac').innerHTML;
document.getElementById('times').innerHTML = t + ' ,' + ct;
}
function timer(){
// Define variables
var frac = Math.round(document.getElementById('frac').innerHTML);
var sec = Math.round(document.getElementById('sec').innerHTML);
// Change decimal and second
frac = frac + 1;
if(frac <= 9){
frac = '0' + frac;
}
else if(frac == 100){
frac = '00';
sec = sec + 1;
}
// Change time displayed
document.getElementById('frac').innerHTML = frac;
document.getElementById('sec').innerHTML = sec;
}
</script>
<table width='1000' height='450'><tr>
<td valign='middle' align='center'>
<font size='7'><span id='time' onkeyup='start()'><span id='sec'>0</span>.<span id='frac'>00</span></span></font>
<br/>
<input type='text' value='START' onkeydown='start()' maxlength='0' size='12' id='startstop'/>
<br/><br/>
<span id='times'></span>
</td>
</tr></table>
As you can see, under stop(), I put the clear.interval. I've tried putting in window.clear.interval and/or window.int = ... but none have worked. I was just wondering how I should go about getting it to stop in Firefox. This is actually for a project, and I need a timer to show in the corner, but don't want something larger like qqTimer.
Last edited: