window.setInterval() : Window Object : Window JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Window » Window Object »

 

window.setInterval()











Syntax








window.setInterval(expression, milliseconds)
    window.setInterval(function, milliseconds)
    window.setInterval(function, milliseconds, arg1, ..., argN)



The setInterval() method sets an interval to invoke the expression or function that is passed to the method.

The expression or function is invoked after every elapse of the milliseconds passed.

This interval can be cleared by using the clearInterval() method.












<html>
    <head>
    <script language="JavaScript1.2">
    <!--
    var counter = 1;

    function startCounter(){
      document.myForm.myText.value = counter++;
    }

    function stopCounter(){
      window.clearInterval(myInterval);
    }
    var myInterval = window.setInterval("startCounter()"5000)
    -->
    </script>
    </head>
    <body onLoad="startCounter()">
    <form name="myForm">
      <input type=TEXT size=20 value="" name="myText">
      <input type=BUTTON value="Clear Interval" onClick="stopCounter()">
    </form>
    </body>
    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Window
» Window Object