...

View Full Version : Form data disappear after browser back button click



ku916
06-20-2002, 05:51 PM
I have a HTML form in 1 JSP, when onSubmit, it post data to a 2nd JSP. In the 2nd JSP, I have a date field that allows user to select date from a pop-up calendar (javascript). Here is something strange I've discovered when user click the 'back" browser button

1. If the pop-up get activated in 2nd, all form data in 1st JSP are lost
2. If the pop-up didn't get activate, all from data in 1st JSP are preserve

Why? I thought the browser back button will get whatever that was stored in the client's local browser history ....

Ku :cool:

JohnKrutsch
06-20-2002, 07:23 PM
Do you have a url where we can see this in action?

ku916
06-20-2002, 08:46 PM
I'm not sure if you can see much, because all the JSP are executed at server-side, I guess you can still get to the javascript and the HTML. Try this link ....

http://141.154.21.206:8080/test/cmp_list_request.jsp?state=new&source=camp_tactic_tab

Try to enter some text in the first screen and the click the "Selection Criteria" button to the the next screen. In the "Selection Criteria", if you click browser "back" you will get back to List Request screen with all the previously entered data.
But if you click on the little calendar (pop-up) beside the "User Due Date" text field and click "back" all the data are lost ....


Let me know what you think?

JohnKrutsch
06-20-2002, 09:06 PM
I don't think this is causing the problem but it is throwing up errors, so cahnge this:

<input type="image" name="selection criteria" src="selection_criteria_button.gif" onClick="return request_validate(this);">

to this:

<input type="image" name="selection criteria" src="selection_criteria_button.gif">

You are already doing the validation with the onsubmit of the form.

I ll keep looking fo rother stuff. Anyone else should feel free to jump in as well.

JohnKrutsch
06-20-2002, 09:10 PM
Also try changing your link that calls the calendar to this:

<a href="#" onclick="show_calendar('document.job_form.user_due_date', document.job_form.user_due_date.value);return false;">
<img src="cal.gif" width="16" height="16" border="0"></a>


This way we don't use href to invoke the call to the function.

ku916
06-21-2002, 01:57 AM
Tried both, didn't work.

However, I did created 2 pages (HTML) without any JSP code and they seems to work. So could it be possible that for JSP, the browser back button actually execute the JSP code again to create the HTML, instead of bring out the previous HTML from browser's cache?

wild guess here!

whammy
06-21-2002, 02:22 AM
I definitely don't think that's the case... unless you send a request to the server specifically (which clicking the back button in your browser doesn't do), you're not going to execute ANY server-side code, no matter what the language.

I wish I had an explanation for it... I'm not familiar with JSP though, so I can't really help in that area :-/

ku916
06-25-2002, 05:48 PM
I've changed my approach to the problem ...

Instead of letting users hit "back" button to go vack in history, I've disabled all browser back buttons and created a link that is pointing to the previous URI (using request.getHeader("Referer") in JSP).

However, I've got myself into a whole different problem. When someone submit the 1st page, there is a javascript to do data validations, if no errors submit the form to a hidden page (perform a single row database insert stmt). But it seems that 2 rows will get inserted into the database instead of 1.

Looking at the javascripts and the event handlers that call them, it seems that the form was being submitted twice

code below:
<html>
<head>
<script language="Javascript">
function request_validate(x){
valid_form = true;
if (x.job_name.value == "") {
valid_form=false;
alert('Job Name is empty');
}
if (valid_form) {
x.submit();
}
else
return false;
}
<!-- history.go(1); -->
</script>
</head>


<body text="#000000" marginwidth=0 leftmargin=0 rightmargin=0 topmargin=10 bgcolor="#e5e5e5" link="#e5e5e5" vlink="#e5e5e5" alink="#e5e5e5"
>
<div align=center>

<FORM NAME="camp_info_form" ACTION="cmp_list_request_insert.jsp" METHOD="post" onSubmit="return request_validate(this);">
<a href ="cmp_job_search.jsp?state=new&source=list_copy"><img src=copy_job.gif></a>
<input type="image" name="selection criteria" src="selection_criteria_button.gif">
</TD>
</TR>
</TABLE>
</FORM>

</body>
</html>

so I've removed the onSubmit in <FORM> tag (thanks from John) and put the call in the image to look like this
<input type="image" name="selection criteria" src="selection_criteria_button.gif" onClick="return request_validate(this);">


now when I hit the submit, it will submit the form (only once ~ great), but it skips the data validations?

I'm so close .... just need little more pointers for javascript ....
thanks
Ku

JohnKrutsch
06-25-2002, 06:30 PM
When using the input type of image, it functions as a submit button. When you have code in there like this:

<input type="image" name="selection criteria" src="selection_criteria_button.gif" onClick="return request_validate(this);">

you are asking it to validate the image as this is referening to the input tag you are in. Try having the form tag like this:

<FORM NAME="camp_info_form" ACTION="cmp_list_request_insert.jsp" METHOD="post" onSubmit="return request_validate(this);">

and your image submit button like this:

<input type="image" name="selection criteria" src="selection_criteria_button.gif">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum