Timer notes > Interval timer

Start a counter that counts down from ten to zero at one-second intervals in the window status bar when you click the button.


The JavaScript:

var intervalTimer;
var counter = 10;

function startCounting( )
{
    intervalTimer = window.setInterval( "countDown()", 1000 );
    window.status = counter;    // show the initial value
}

function countDown( )
{
    if (counter > 0)
    {
        counter = counter - 1;
        window.status = counter;
    }
}

<form name="myForm" action="#">
<input type="button" value="Start counting" 
    onclick="startCounting( )" />
</form>