SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Recursive timer by using setTimeout

We need to execute a function or code block at a fixed interval to carry out some routine work. Here we need a triggering function which will start the required function at a definite time gap. To do this we will use our setTimeout function. setTimeout JavaScript built in function we will use inside a user defined function and we will call the same function within it to make it recursive. We will be using one alert to display a message at every interval.

Here is the demo of recursive timer

Here is the code.
<html>
<head>

<script type="text/javascript">

function disp(){
alert("Hello");
}

function timer(){
disp();
setTimeout('timer()',5000);
}

</script>

</head>
<body onLoad="timer();">

</body>
</html>

Found anything wrong or wants to improve the code by adding more features? Post your short comment here or use the Forum



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Date & Time
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer