Tuesday, January 1, 2013

Timer

How to set Timer using Javascript.

Below code explains how to set a timer and stop a timer, you will also find a working example regarding the same.


<form name="f1">
<input type="text" id="but" />
<input type="button" value="start" onclick="timer()" name="theButton" />
<input type="button" value="stop" onclick="stoptimer()" />
</form>

<script type="text/javascript">
var count=0;
var x;
function timer(){
x=setTimeout("timer()",1000);
count=count+1;
document.getElementById("but").value=count;
}

function stoptimer(){
clearTimeout(x);
}
</script>


Click the below start and stop button to view the timer.

Informative Javascript

No comments:

Post a Comment