Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <script> var c = 0; var t; var timer_is_on = 0; function timedCount() { document.getElementById('txt').value = c; c = c+1; t = setTimeout(function(){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> <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. Click on the "Start count!" button to start the timer again. </p> </body> <!-- Mirrored from www.w3schools.com/js/tryit.asp?filename=tryjs_timing_stop by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 07:37:28 GMT --> </html>
Result:
Try it Yourself - © w3schools.com