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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts

    clear all input, checkbox or radio in form

    Can somebody give me an exaple for a functio that clear all fields, radio buttoms, checkbox in one form?


    Best Regards

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function ResetIPs(){
    // document.fred.reset(); // this line for all form elements
    
    // these lines for specified elements
     var args=ResetIPs.arguments;
     for (var zxc0=0;zxc0<args.length;zxc0++){
      var fld=document.getElementsByName(args[zxc0]);
      for (var zxc0a=0;zxc0a<fld.length;zxc0a++){
       if (fld[zxc0a].type=='text'){ fld[zxc0a].value=''; }
       if (fld[zxc0a].type=='radio'||fld[zxc0a].type=='radio'){ fld[zxc0a].checked=false; }
      }
     }
    }
    
    /*]]>*/
    </script>
    </head>
    
    <body onload=ResetIPs('n1','n2','n4','n5')>
    <form name="fred" >
    <input name="n1" />
    <input name="n2" />
    <input name="n3" />
    <input name="n4" />
    <input type="radio" name="n5"  />
    <input type="radio" name="n5"  />
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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