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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reset a form's values in Internet Explorer

Status
Not open for further replies.

nissan240zx

Programmer
Jun 26, 2005
280
US
Hello All,
Let me first start by saying I am not asking about the submit and reset button in a form. Thats working fine.

The scenario is -
I have a form (jsp) which processes a transaction which when I submit I get the confirmation page.
Now on that same page I also have a button called create new transaction.
When I click that and come to the form, its got all the values from the previous form submission.
Is there any script or feature that I can setup so when I click the create new transaction button it resets, refreshes the form fields and gives me a clean empty form.

Let me know also say that this problem is happening on only one of my machines..and as I cant predict what setting there might be on a potential users machine I want to make this "idiot proof".

Please help..

Nissan.

A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
I have an idea...maybe..
Will my issue be resolved if a Body onload event is fired which would reset my form fields..
Can anyone suggest me how to do that.

soemthing like
Code:
<BODY onLoad="reset_form()">

Code:
<SCRIPT TYPE="text/javascript">
function reset()
{
document.yourFormName.reset();
}
//-->
</SCRIPT>

Will something like thsi work...
Please advice...

A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
Hello Lee,
Could you please explain by wht it means by putting that at the bottom of the page.
Do you mean add it after submit.

I would really prefer it to on the page which loads the form.
For example the first page that user would access is
form_main.jsp. They complete the form and submit it, and gets displayed form_process_complete.jsp. Thsi page has a button to load form_main.jsp
So when they load form_main.jsp, the fields get reset.

Basically what I am saying is everytime form_main.jsp gets loaded all the fields should get reset by default on Body OnLoad.

Hope I am explaining Ok..




A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
At the bottom of the page you want to clear the form on, use this:
Code:
<SCRIPT TYPE="text/javascript">
document.forms['yourFormName'].reset();
//-->
</SCRIPT>

Just remember to change yourFormName to whatever the name of the form on the page is that you're resetting.

Lee
 
I guess I didnt explain the issue I am having..
The reset button on the form works fine..but when it gets reloaded from another link the form elements seems to have the values in them.

A good programmer is someone who looks both ways before crossing a one-way street. - Doug Linder
 
Doing this blind doesn't work, you know. If you want help with some of the code, you should post this in the appropriate forum, probably for whichever server-side scripting language the page is written in.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top