Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Preserving form data and history.back()

JavaScript history forms



4:31 pm on May 6, 2003 (gmt 0)

10+ Year Member

I have a PHP-based form that allows for the upload of two images, in addition to some other user information such as name, company, etc. When the user submits the form, there is some validation that goes on in PHP to ensure that the image is of a certain type and resolution. If one of these tests fails, a message is displayed describing what happened and then I set up a little JavaScript link like such....

<a href="javascript:history.back();">Fix It</a>

To allow the user to return to the original form and re-upload the image. However, when you click on the link, nothing happens. It stays on the same page! If I use the back button in the browser--same thing. I should note that the window the form is in has been created by window.open() and is a window called new_window. I have tried using javascript:new_window.history.back(), to no avail :(

An obvious solution would be to pass all the form variables to the link and just do it via PHP. But I feel like just moving back should do the trick.

It doesn't appear that any caching is going on, but perhaps I just am looking in the wrong place. Anyone haev any idea or tips on preserving form data and using history.back()?

Thanks :)

Incidentally, you can test out the script here:
<sorry, no test URLs>

[edited by: tedster at 6:31 pm (utc) on May 6, 2003]


4:39 pm on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

<a href="#" onclick="javascript:window.opener.history.go(-1);">back</a>


5:30 pm on May 6, 2003 (gmt 0)

10+ Year Member

Thanks for the reply... I don't need the parent window to go back, the form is contained in new_window. I tried the syntax you used minus the 'opener' portion, but IE just ignores it when you click the link. It acts like it went back, but the form does not reappear. Very strange.


6:30 pm on May 6, 2003 (gmt 0)

10+ Year Member

Just FYI, I don't think IE liked the fact that the original form and the processing script were the same. I put the form in a separate file and now using back() works fine.


10:57 pm on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I would skip the "back" idea completely. Why not display the form again, with all the data entered in already, and just an error message telling them what went wrong?

Don't trust every browser to remember the form data on back-click...


Featured Threads

Hot Threads This Week

Hot Threads This Month