...

View Full Version : Clear form after submission



Liz_W
05-23-2005, 11:28 AM
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:


<input name="submit" type="submit" value="submit" onSubmit="document.myform.reset();" />


Anyone know what's wrong? :(

Kor
05-23-2005, 11:45 AM
onsubmit is a form's handler, not a button's handler
try

<body onload ="document.myform.reset()">

coothead
05-23-2005, 11:46 AM
Hi there Liz_W,

try it like this example...


<form action="http://www.codingforums.com/" onsubmit="this.reset()">
<div>
<input type="text"/>
<input type="submit"/>
</div>
</form>

coothead

Liz_W
05-23-2005, 11:54 AM
Thanks KOR it worked, Hi Coothead alas it did not, never mind I've tried at least six other methods :thumbsup:

glenngv
05-23-2005, 12:44 PM
Hi there Liz_W,

try it like this example...


<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.

Kor
05-23-2005, 12:49 PM
...this is the reason for I have used a document.body handler instead of a form's handler.

ReverendTodd
06-03-2005, 06:03 AM
Include this in your HEAD tag

<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.

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum