Skip to main content
Inspiring
February 20, 2009
Question

Automatic Page Reset

  • February 20, 2009
  • 3 replies
  • 1613 views
I have a form that contains two dropdowns.When the values are selected, they are passed to another page and used in a query where statement. When they are done and return to the original page with the pulldowns, the selected values are still populating the boxes. A simple browser refresh will clear the values. However, they do not want to do this and want the page to automatically refresh to clear the values, when they go back in.

The javascript that I have found uses the meta tag but is set at intervals, which is not what I want. Other code uses the body onload but that seems to be an infinite loop.

Where can I find code to refresh the page once only, as soon as it is accessed. ?

thanks
    This topic has been closed for replies.

    3 replies

    Inspiring
    February 20, 2009
    How are you going back to the original page?
    trojnfnAuthor
    Inspiring
    February 20, 2009
    To go back, they either use the browser back button, or a javascript button (onClick="history.go(-1)) that I have included at the end of the page.
    Inspiring
    February 20, 2009
    quote:

    Originally posted by: trojnfn
    To go back, they either use the browser back button, or a javascript button (onClick="history.go(-1)) that I have included at the end of the page.

    That's why they have to refresh. If you change the js button to window.location(url), the page will refresh itself.

    Do they have any other choices besides going back to the form? If not, you can cflocate them there.
    Matt Gifford
    Participating Frequently
    February 20, 2009
    Hey

    Have a look at the following link. It will do everything that you need to do (assuming I have understood your requirements of course)

    http://www.learningjquery.com/2007/08/clearing-form-data

    You'll need to download the latest version of jQuery (jquery.com) and place within your head tag, and place the function written in the above tutorial within normal <script></script> tags.

    Hope that helps. Any problems, give me a shout.
    trojnfnAuthor
    Inspiring
    February 20, 2009
    Thanks Matt, I will take a look and give it a try.
    Matt Gifford
    Participating Frequently
    February 20, 2009
    Hi trojnfn

    Are you submitting the data via ajax, or to a new page as a form post?

    Either way, jQuery will do everything that you need (and more)

    If it's an AJAX call, you can set the selected option/index of the select box within the ajax function 'success' param, which will run any functions declared within it after the AJAX has been successful.

    If you are doing a page refresh/relocate, you could use the onready function to set whatever values you wanted:

    $(document).ready(function() {
    // put all your jQuery goodness in here.
    });

    Hope that helps.
    Any questions, feel free to ask.
    trojnfnAuthor
    Inspiring
    February 20, 2009
    Hello Matt,

    Thanks for the response.

    The form is submitted via form post. I am not familiar with jQuery.

    As soon as the form (with the pulldowns) is entered, whether it is the very first time, or returned from the other page, I want it to refresh once only (to clear/reset selections).

    Does the code do that, and where would it go, inside regular javascript tag ?