setInterval(): calls at specified intervals (in milliseconds)

<script language=javascript>

function to_start(){
tm=window.setInterval('disp()',1000);
}

function disp(){
document.getElementById('n1').innerHTML += ' plus2net.com ';
}
</script>

Demo of SetInterval() to print at an interval of 1 second.
In JavaScript we can call recursively any function at a particular interval by using setInterval() method of window object.
Here is the syntax
setInteval('function_name', time-millisecond, lang);
In above code function_name is the name of the function we want to execute at an interval of time-millisecond ( time in mill second ) , optional element lang we can specify the code we want to execute.

Let us start displaying current (changing ) time by using toTimeString() function. We will keep display part inside a function disp() . Using setInterval method we will call disp() function in every one second ( 1000 millisecond ) .
Demo of SetInterval() : Real time clock refreshing in 1 second.
Here is the code.
<html>
<head>
<title>Demo of SetInterval JavaScript function</title>
<script language=javascript> function to_start(){ tm=window.setInterval('disp()',1000); } function disp(){ var dt= new Date(); var str=dt.toTimeString() document.getElementById('n1').value=str; } </script> </head> <body > <input type=text id=n1 > <input type="button" name="btn" value="Start" onclick="to_start()";> </body> </html>
Above code we will only display the change in time but we can't stop it.
setTimeout() Stopwatch script using setInterval() Stop setInterval() method by window.clearInterval()

Window Object Bookmark a page Redirect Page
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    sathya

    26-03-2013

    how to get a alert message with the reference of table data id using javascript?
    Note: if i clicked one row and the alert box will be triggered with that row information... can u please help me???? for this question? i need soon back

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer