Javascript – 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 this would be the case, i have jQuery on the site but couldnt get delay() working either

<form action="" name="cartCheckout" id="cartCheckout" method="post"> 
<input type="hidden" name="action" value="checkout" />
<input type="hidden" name="save" value="1" />
<input type="hidden" name="orderID" value="<?php echo $GLOBALS['CHECKOUT_ORDERID']; ?>" />

<div class="itembox" id="step4box">
    <div id="progress">
        <li>Your Cart</li>
        <li>Your Details</li>
        <li class="current">Payment</li>
<div id="words" class="gothbold">Please wait while we we redirect you to<br />Paypal for a secure payment method.</div>

<a class="redirect" href="javascript:void(0)" title="Proceed to Paypal" onClick="document.cartCheckout.submit();"><span>If you aren't redirected in 5 seconds click here</span></a><br />

<a class="cancel" href="javascript:void(0)" title="Return to details" onClick="jQuery('#step4box').hide();jQuery('#step2box').show();"><span>Cancel</span></a>    
<script type="text/javascript">
        window.setTimeout(document.cartCheckout.submit(), 5000);

any help would be greatly appreciated, thanks in advance


changed to this via a combination of @Alex, @user824294 and this question: How Can I create A 5 second Countdown timer with jquery that ends with a login popup?. Now working great and with great functionality of a countdown. Thanks guys!

    var counter = 5;
    var interval = setInterval(function() {
        if (counter == 0) {
    }, 1000);


function redirect() {

Best Solution

Pass a reference to the function instead.

    window.setTimeout(document.cartCheckout.submit.bind(document.cartCheckout), 5000);


    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.