File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes reset form inside frame after submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "reset form inside frame after submit" Watch "reset form inside frame after submit" New topic
Author

reset form inside frame after submit

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
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?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
You are welcome for wasting part of my day which I will never get back! lol

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reset form inside frame after submit
 
Similar Threads
results in same page not working
anyone can help with alert in jscript ?
How do I update the values in my selectOneMenu?
Question about forms
form submitting on html link