Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-23-2005, 11:28 AM   PM User | #1
Liz_W
New Coder

 
Join Date: Feb 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Liz_W is an unknown quantity at this point
Clear form after submission

I have tried several methods to clear my form after submission and none seem to work, I hit the back buton and the form data is still selected.

This is what i tried last:
Code:
<input name="submit" type="submit" value="submit" onSubmit="document.myform.reset();" />
Anyone know what's wrong?

Last edited by Liz_W; 05-23-2005 at 11:41 AM..
Liz_W is offline   Reply With Quote
Old 05-23-2005, 11:45 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
onsubmit is a form's handler, not a button's handler
try

<body onload ="document.myform.reset()">
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 05-23-2005, 11:46 AM   PM User | #3
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,555
Thanks: 0
Thanked 196 Times in 192 Posts
coothead will become famous soon enough
Hi there Liz_W,

try it like this example...

Code:
<form action="http://www.codingforums.com/" onsubmit="this.reset()">
<div>
<input type="text"/>
<input type="submit"/>
</div>
</form>
coothead
coothead is offline   Reply With Quote
Old 05-23-2005, 11:54 AM   PM User | #4
Liz_W
New Coder

 
Join Date: Feb 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Liz_W is an unknown quantity at this point
Success

Thanks KOR it worked, Hi Coothead alas it did not, never mind I've tried at least six other methods
Liz_W is offline   Reply With Quote
Old 05-23-2005, 12:44 PM   PM User | #5
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Quote:
Originally Posted by coothead
Hi there Liz_W,

try it like this example...

Code:
<form action="http://www.codingforums.com/" onsubmit="this.reset()">
<div>
<input type="text"/>
<input type="submit"/>
</div>
</form>
coothead
As Liz said, it doesn't work. That is because the reset values (defaults) are the ones submitted to the server. It resets the form before it is submitted.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 05-23-2005, 12:49 PM   PM User | #6
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
...this is the reason for I have used a document.body handler instead of a form's handler.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 06-03-2005, 06:03 AM   PM User | #7
ReverendTodd
New to the CF scene

 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ReverendTodd is an unknown quantity at this point
Include this in your HEAD tag
Code:
<SCRIPT LANGUAGE=\"JavaScript\"> <!-- 
	function clearForm(formName){
		setTimeout(formName+'.reset()',1000);
		return true;
	}
--> </SCRIPT>
Then simply include this in the tag of any form you want to clear after submitting.
NOTE: Be sure to name your forms by having a NAME='give the form a name here' in the form tag as well.
Code:
onSubmit='return clearForm(this.name)'
If the user's browser supports javascript this will clear the form after submittion...If not it should submit normally.
ReverendTodd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 AM.


Advertisement
Log in to turn off these ads.