Hi I want to put a time delay on a function. This is how I'm going implementing it, however it's not working......
function loadXMLDoc()
{
setTimeout('loadXMLDoc()',5000);
//code
....
..
..
.
}
| SitePoint Sponsor |

Hi I want to put a time delay on a function. This is how I'm going implementing it, however it's not working......
function loadXMLDoc()
{
setTimeout('loadXMLDoc()',5000);
//code
....
..
..
.
}

Try moving the set|Timeout after the rest of the code (assuming you want the code to constantly repeat with the delay in between) or after the function completely if you just want it to run once after the delay.
orCode:function loadXMLDoc() { //code .... .. .. . setTimeout(loadXMLDoc,5000); }
Code:function loadXMLDoc() { //code .... .. .. . } setTimeout(loadXMLDoc,5000);
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">

Hi Stephen, yes I tried these earlier, but it didn't work

Oddly enough when I try this code below, the submission of the button goes out of control
Code:function loadXMLDoc() { //code .... .. .. . setTimeout(loadXMLDoc,5000); }


How about using setInterval instead?
Code javascript:function loadXMLDoc() { //code .... .. .. . } setInterval(loadXMLDoc, 5000);
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
Bookmarks