Skip to content Skip to sidebar Skip to footer

Auto Submit Form After 5 Seconds

I have a form that i am trying to submit after the page loads and 5 seconds has gone passed.. i have tried setTimeout but it doesnt appear to be working.. can anyone suggest why th

Solution 1:

Pass a reference to the function instead.

window.onload=function(){ 
    window.setTimeout(document.cartCheckout.submit.bind(document.cartCheckout), 5000);
};

...or...

window.onload=function(){ 
    window.setTimeout(function() { document.cartCheckout.submit(); }, 5000);
};

You are currently executing the function, and then passing its return value to setTimeout().

Also, if you wish to execute closer to exactly 5 seconds, you'd need to a setInterval() or recursive setTimeout() and examine +new Date.

Solution 2:

You can have it realy simple, try this guys :

<formname="xyz"...>
...
<scripttype="text/javascript"><!--
   var wait=setTimeout("document.xyz.submit();",5000);
//--></script></form>

Solution 3:

Try doing this instead:

window.onload=function(){ 
    window.setTimeout("redirect()", 5000);
    // ORwindow.setTimeout(function() { redirect(); }, 5000);
};

functionredirect() {
    document.cartCheckout.submit();
}

Post a Comment for "Auto Submit Form After 5 Seconds"