Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reset form inside frame after submit

 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being rather new to JavaScript, I'm having trouble resetting my text field after I submit.

Either it resets my form (in the left frame) before submit and I get the wrong results in my right frame, or I get the right results but the field doesn't clear.

Any hints?
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best solution would be to add an onload function into the right frame which resets the form fields in the left frame.

You can call a function in the right frame by

parent.frameName.function();

Eric
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I put my function (same as above) into the head of the right_frame (the result frame). I put this into script tags in the body of the right_frame, where search_form_1 is the name of the form in nav_panel that I want to clear, but it still isn't working. I get "Error: search_form_1 is not defined". What am I doing wrong? Is there a better way to refer to the form that I want to clear in the nav_panel frame?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is because it has no clue what search_form_1 is. It thinks that it is a variable in the script.

This is how I would personally reset a form

if the basic
document.formName.reset();
does not work, than I would do this



All you do is pass the form name to the function.

Eric
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.formName.reset();
doesn't work for some reason.

But my question is more along the lines of How do I reference the form in the other frame? If I just call it by name, it is not recognized. Do I need to do something like
parent.nav_panel.ResetForm( parent.nav_panel.xFormName );
in order to pass in the form name?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the example I posted, I am just passing a string with the name of the form. The script than gets the form object with the name.

with the script you were using, you would of have to do this
onload="parent.nav_panel.reset_form(parent.nav_panel.document.search_form_1)";


with the function I posted you would have to do this:
onload="parent.nav_panel.ResetForm('search_form_1')"

A simple test to check if you are referencing the form correctly, you could do this:
onload="alert(parent.nav_panel.document.search_form_1.elements.length)"
it should display the number of elements in your form.

This line:
onload="parent.nav_panel.document.search_form_1.reset()"
sets the form to its initial state. So if it had values to start with it will go back to those values, it does not blank them out.
[edit - whoops had extra ) in the last code example]


Eric
[ May 25, 2005: Message edited by: Eric Pascarello ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You gave me my blog idea for today, I was lost for ideas!
http://radio.javaranch.com/pascarello/2005/05/25/1117043999998.html

Eric
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Eric.

I put the function ResetForm in the nav_panel and called it with on load="parent.nav_panel.ResetForm('search_form_1')" in the body tag in the results frame.

It worked perfectly.
[ May 26, 2005: Message edited by: Marilyn de Queiroz ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome for wasting part of my day which I will never get back! lol

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic