I am wondering why this code does not work. When I put it inside the onload function, it does not work, and I am not sure why. I have a lot of other code in the onload function, but I have deleted it for this example. Anyway the other code works fine, only this part does not.
window.onload = function() {
var i, timer, divide;
i = 0;
divide = 100;
function start() {
timer = self.setInterval("increment()", (1000 / divide));
}
function increment() {
i++;
document.getElementById("timer_out").innerHTML = (i / divide);
}
function stop() {
clearInterval(timer);
timer = null;
}
function reset() {
stop();
i = 0;
document.getElementById("timer_out").innerHTML = (i / divide);
}
}
<div>
<span id="timer_out">0</span>
</br>
<input type="button" value="Start" onclick="start()"/>
<input type="button" value="Stop" onclick="stop()"/>
<input type="button" value="Reset" onclick="reset()"/>
</div>