Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset form values on Back Button

Status
Not open for further replies.

beanbrain

Programmer
Dec 31, 2001
170
I have a form that I want to reset after submission.

Once the form is submitted the values of the fields are submitted to a perl script which sents a verification back in the form of simple HTML code. When I hit the "Back" button I want the form to reset so that an end user cannot resend the same data by accident.

I have the following in the HEAD section of the form.

Code:
if (location.search == '') {
    setTimeout('location += \'?reloaded\';', 500);
}
window.onload = function() {
  if (location.search && location.search.length > 0) {
    document.THISFORM.reset();
  }
}

The form attributes are as follows.

Code:
<FORM METHOD=POST NAME="THISFORM" ACTION="[URL unfurl="true"]http://www.mylocation.org/cgi-bin/borf/process-pick.pl"[/URL] ONSUBMIT="javascript:return FormCheck(this)">

Sometimes the form resets on the back button and sometimes not.

Note: I am calling this form from within another HTML page set up with two frames. This form being the top frame and a form that passes account numbers being the bottom frame.



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
There's no quick and easy way of doing this unfortuntaely.

However, you can use cookies to track if a page is revisited, and clear all the fields during the onload handler of the page.

Do a google search for javascript cookies to get you started in the right direction.

-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
Khat:

Great suggestion, but I'm not allowed to use cookies.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OK. Got it from another post.

Adding this;

Code:
<body onLoad="top.framename.myForm.reset();">

to the body statement solved the problem. Where framename is the name of the calling frame and myForm is the name of the form.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top