x
<html>
<head>
<script>
//Counter increments every 1s.
var counter = setInterval(function(){startCount()},1000);
//Counter starts from 1.
var initVal = 1;
function startCount(){
//Counter value is displayed in text box.
var count = document.getElementById('txtBox');
count.value = initVal++;
}
</script>
</head>
<body>
<input type="text" id="txtBox">
<br/><br/>
<button onclick="startCount()">Start Counter</button>
<button onclick = "clearInterval(counter)">Stop Counter</button>
<p>Buttons to start and stop counter. clearInterval() stops counter.</p>
</body>
</html>
Comments
No comments have been made yet.
Please login to leave a comment. Login now