Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form data disappear after browser back button click

    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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Do you have a url where we can see this in action?

  • #3
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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_...amp_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?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #6
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 :-/
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    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">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •