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

Clearing form on submit 3

Status
Not open for further replies.

emozley

Technical User
Joined
Jan 14, 2003
Messages
769
Location
GB
Hi,

I have a form that submits data to a script that is executed in a separate frame so I need to clear the form once this has been done. I've had a look round and found the following:

document.myForm.reset();

which apparently has to be used with onSubmit somehow.

How would I adapt the following?

<form name="myForm" method="post" action="addrecord.asp">
<input type="text" name="UserName"><br>
<input type="submit" value="Add Record">
</form>

 
I have tried changing the first line to

<form name="myForm" method="POST" action="addcontact.asp" onSubmit="document.myForm.reset();">

But when I click submit the form is cleared but what I typed is not added to the database.
 
...submits data to a script...
Are you referring to a javascript? I think not by looking at the code you posted (it'd be easy if you did). Are you referring to the "addrecord.asp" as a script? If so... how are you targetting the frame from this? If you are using javascript already... this will be easy.

Do you have a URL available.. or the (cut down) client-side code for the page that has the "submit" button on it?

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Ideally I would like to submit the contents of the form to my ASP script in the normal way but I would like to use Javascript to clear the form.

I've used the tag <base target="middle1"> to specify which frame the list of names is displayed in.

cheers

Ed
 
If you want to clear the form [!]after[/!] its data has been submitted, then you cannot use the onsubmit event, as this fires before the submission.

The only way to do this would be to have a callback function in your form page that does this, and that function is only called by the target frame once it has received the form data.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Actually, saying that's the only way is untrue... you could simply call the form frame's form reset method directly from the target frame, bypassing the need for an extra function.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
If you clear the form before you send it, you will have no data to populate the database through your asp script.

Why not just redirect back to the form from your asp page after your update has worked ?

 
How about using javascript to collect the contents of the form and massage them into a GET url which you then set as the location for the frame. That'll work. Just got to handle some escaping and targetting the frame from javascript.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I think the idea

"could simply call the form frame's form reset method directly from the target frame, bypassing the need for an extra function."

is the best option - the form is in a frame called middle and the other page is in a frame called middle1. How would I reset the form from that page?

Thanks very much
 



if you send the data to addrecord.asp, unless there is a server side redirect on that page, then addrecord.asp will be the page displayed in the form ??

if you are targeting another frame for the update then when this page reloads, ie addrecord.asp, you can add <body onLoad="top.framename.myForm.reset();"> which will reset the form, also you will need to target the frame with the first form.

<form target="framename" ...

Hope this all makes sense.

 
Perfect that's nailed it!

Thanks very much.

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top