Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 12:41 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    onsubmit is a form's handler, not a button's handler
    try

    <body onload ="document.myform.reset()">
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,743
    Thanks
    0
    Thanked 244 Times in 239 Posts
    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

  • #4
    New Coder
    Join Date
    Feb 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Success

    Thanks KOR it worked, Hi Coothead alas it did not, never mind I've tried at least six other methods

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ...this is the reason for I have used a document.body handler instead of a form's handler.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •