Reputation: 3
I'm trying trying to submit a form to a new window and redirect the current window but its not working. my code is:
function submit() {
document.checkout_confirmation.submit();
setTimeout(window.location = 'http://google.nl', 1000);
}
when i execute this code it only redirects the page and doesn't submit the from. am i doing this wrong or is this inpossible? Feel free to ask if my question is missing any details Thanks in advance
Upvotes: 0
Views: 2504
Reputation: 403
The correct thing to do is have your server redirect the user after a successful submission. What if something about the form is invalid? You don't want to redirect in that case, and you can't just trust your JavaScript code to validate (for it can be disabled). See Post/Redirect/Get.
Also, you are using setTimeout incorrectly, not that it is likely to work when you are already sending the browser somewhere else via submit() (there is always the possibility that your form only fires other "submit" listeners and sends via Ajax, I suppose). It should look like this:
setTimeout(function() {
window.location = 'http://google.nl/';
}, 1000);
Upvotes: 4