window.setInterval

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 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

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.
Visitors Rating
Your Rating





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 Comment This is for short comments only. Use the forum for more discussions.




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer