How to Interval Timer Countdown using setTimeout()

window.setTimeout() allows you to specify that a piece of JavaScript code (called an expression) will be run a specified number of milliseconds from when the setTimeout() method was called. You may also like How to converting pacific time string to time in PHP and How to get Page Loading Time using PHP.

HTML Code

<input id="timer_count" type="text">

Jquery Code

var i = 0;
var myVar;
function onTimer() {
    $('#timer_count').val(i);
    i++;
    myVar = setTimeout(onTimer, 1000);
} 
onTimer();

function ClearTime()
{
    i = 0;
    clearTimeout(myVar);
    onTimer();
}

Leave a Reply

Your email address will not be published. Required fields are marked *