Time delay on a function

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.

function loadXMLDoc()
{
//code
....
..

..
.
setTimeout(loadXMLDoc,5000);
}

or

function loadXMLDoc()
{
//code
....
..

..
.
}
setTimeout(loadXMLDoc,5000);

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


function loadXMLDoc()
{
//code
....
..

..
.
setTimeout(loadXMLDoc,5000);
}

How about using setInterval instead?


function loadXMLDoc()
{
//code
....
..

..
.
}
setInterval(loadXMLDoc, 5000);