Click to See Complete Forum and Search --> : window.location.replace doesn't work?


sharapov
11-21-2003, 12:38 PM
Hello,

I have a form that I am submiting. What I want is to call "window.location.replace" when form is submited to prevent users from going back to the form by pressing back button. Below is the code I use, however when I submit the form I can still use back button to go the form. Can anybody help?



<form onsubmit="window.location.replace('1.php');" method="POST" action="3.php">
<select size="1" name="D1"></select>
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2">
</form>

gil davis
11-21-2003, 12:46 PM
Sounds like a race. You are essentially telling the browser to load "1.php" when you submit the form and then the action part tells the browser to load "3.php".

And I'll bet you thought you had a clever way of preventing duplicate form submission. ;)

The easiest thing to do is to declare default values in each form field and do:
onload="document.formname.reset()"

sharapov
11-21-2003, 12:51 PM
gil davis,

Well, I was actually trying to prevent users from going to the form page all together. Is there way for both "location.replace" and form submision to win that race? :D

gil davis
11-21-2003, 12:58 PM
Not really. It's a security thing. You cannot modify the history of the user's browser, and that is basically what you are trying to do. You are allowed to affect only the current history entry, and you would need to clobber the previous one.

I suppose you could fake out the action by returning false to the onsubmit and then adding the form string to the href. According to http://developer.netscape.com/viewsource/goodman_url_pass/goodman_url_pass.html you can append the form data to the URL the same way the form does. A big form would be a royal pain.