#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    55
    Rep Power
    15

    Default values on the form on page reload


    My question is about how to get the default selections on the HTML page after submitting the form and going Back, and on reload. Following is the scenario:

    After the user makes selections on the radio buttons on the HTML form and submits the form, the user is directed to another HTML page. When the user clicks the (IE) browser's 'Back' and returns to the previous HTML page, the page is displayed with the selections made. Is there a way to get the default selections using javascript? Or should I change something on the 'Internet Options'

    Also, when the user makes the selections on the radio buttons and reloads the page without submitting the form, the selections are not the default ones. Is this also a browser issue?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    802
    Rep Power
    105
    Put a script after the </form> tag that calls the reset() method of the form...
    Code:
    <script type="text/javascript">
    document.formname.reset();
    </script>
    The form will be reset when the page loads, even if the browser had "remembered" previous values.

    The script can actually be anywhere on the page as long as the script gets executed after the form is created. So the script must be either "below" the form on the page, or in a function that is called from "below" the form or called onload.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    55
    Rep Power
    15
    I added a function to onload in the form attributes. But it is not working even when I do a reload or go back to the page after submitting.

    The first time I open the browser, open the page, make selections and reload it gives me the default selections. But if I make selections again and reload it does not work.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    802
    Rep Power
    105
    Hmmm... putting the code in the body of the document seems not to work, since apparently the form is repopulated after the page loads. When you say you put it in the onload event on the form attributes, you used <form ... onload=...>? I am not sure if a form has an onload event. However putting the command in the body onload event worked for me...
    Code:
    <body onload="document.formname.reset();">
    Is this what you tried and it did not work? When I tried it, the form was reset no matter how many times I changed the field and pressed F5.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    55
    Rep Power
    15
    Thank you so much. It worked when I had the onload in the <body>. I was using the onload in the <form> before.

IMN logo majestic logo threadwatch logo seochat tools logo