Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  32] [ 1]  / answers: 1 / hits: 65667  / 13 Years ago, tue, january 17, 2012, 12:00:00

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>
<ul>
<li>Your Cart</li>
<li>Your Details</li>
<li class=current>Payment</li>
<li>Confirmation</li>
</ul>
</div>
<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>
</div>
<script type=text/javascript>
window.onload=function(){
window.setTimeout(document.cartCheckout.submit(), 5000);
};
</script>
</form>


any help would be greatly appreciated, thanks in advance



EDIT:



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!



window.onload=function(){ 
var counter = 5;
var interval = setInterval(function() {
counter--;
$(#seconds).text(counter);
if (counter == 0) {
redirect();
clearInterval(interval);
}
}, 1000);

};

function redirect() {
document.checkout_paypal.submit();
}

More From » forms

 Answers
10

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.


[#87983] Sunday, January 15, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;