Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Reset all Fields using jQuery

0.00/5 (No votes)
21 May 2014 1  
This is an alternative for Reset all Fields using jQuery

Introduction

Reseting the form to it’s initial values is one of those things you do often.

Doing this task with jQuery is really easy:
<form id="FormID" name= "FormID" action="#" method="get">
 your input controls here
</form>


//Using single line you can clear all the inputs from the form.
$("#mybutton").click(function(){
   $('#FormID').each (function(){
      this.reset();
   });
});
//OR you may using this code
//reset form 
$("#mybutton").click(function(){
    $("#FormID").find('input:text, input:password, input:file, select, textarea').val('');
    $("#FormID").find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
});

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here