wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes history.back problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "history.back problem" Watch "history.back problem" New topic
Author

history.back problem

Anthea Blake
Greenhorn

Joined: Apr 18, 2002
Posts: 22
Hi,
I am using the history.back function to go back to a previous page. The problem is that the previous page contains a validation function, written in javascript, to validate the current page before going to the next page and when I click the back button on the next page to go to the previous page, the error message which popped up from the validation on the previous page, pops up again before loading the previous page.
Does anyone know what I can do so that the previous validation message does not pop back up again when I use the back button.
Any help is greatly appreciated.
Thank you,
Anthea
Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
The back button and history.back() have been the bane of most web app developers since, like... FOREVER. There is no easy fix that i have found, (and believe me i have looked.) But here are some ideas...
First of all, what triggers the validation method?
It sounds like the body onload event handler. If this is the case you might try to use a different handler.
If you can't change the the handler you might want to try to have the button regenerate the page supplying the valid data or disabling the validation routine altogether. This is a little combersome ,but it should work.
Anthea Blake
Greenhorn

Joined: Apr 18, 2002
Posts: 22
Hi,
Thanks for your response.
I don't have an event handler in my onload part of the page.
My validation handler is a javascript function that is called when the user clicks a button to go to the next page. History.back is called when the user clicks a button called "back" on the next page. I am not referring to the browser's back button, but my own back button I created for the page.

You mentioned that I could disable the validation altogether. Do you know how I could do this. Is there some function I could use?
Any help is appreciated.
Thank you,
Anthea
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
Hi Anthea,
Are you creating something like an index of pages or something? If so, your best bet (least what I get from your message) is to set a hidden field on your page, once into it. Upon clicking the button set it to something else. Heres the small trick. When you do click the button check first on the state of the value in the hidden field. If it is, say, 1 coming in and it turns to 2 when you click the button to leave the page, it should be 2 when you go back to it as well. This way you know you have been there before. I hope this is something on the lines you were looking for.
Rob
swaroop shastri
Ranch Hand

Joined: Aug 15, 2001
Posts: 65
Here is a useful link.
http://developer.netscape.com/docs/manuals/communicator/jsref/wina2.htm
One solution to your problem, is try to get the "history.current" location. Check the history.length. Also check to see if there are more history items that occur after the history.current. If they do, then you are sure that the user has hit the back button. i have not done this myself, but just and idea. Please do let us know if you have found out anything that works. One more idea could be using cookies.
Anthea Blake
Greenhorn

Joined: Apr 18, 2002
Posts: 22
Hi,
Thank you very much for all your responses.

The page I am using is a form that contains a list of information that the user has to fill in. Before the user can go to the next page, the page is validated with javascript to see if any fields are missing. If any fields are missing an error message is displayed using javascript. The user then clicks ok on the error message, and fills in all the fields. Once all the fields are filled in, the user can then go to the next page. The problem I had was that the next page has an HTML "back" button that goes to the previous page. If a validation error had previously occured on the previous page, that error pops up again when I used history.back, even though the page was not loaded yet. So I needed to get rid of the error message popping up again when I go back to the previous page.
I'm not sure if I explained it well enough, but thanks a lot for all you responses. I am currently not using the "history.back" function anymore. I just decided to save the previous forms data in a temporary table and just reload the data that the user entered before they went to the next page.
Thanks a lot again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: history.back problem