jQuery/Javascript function to clear all the fields of a form [duplicate]

Note: this answer is relevant to resetting form fields, not clearing fields – see update.

You can use JavaScript’s native reset() method to reset the entire form to its default state.

Example provided by Ryan:

$('#myForm')[0].reset();

Note: This may not reset certain fields, such as type="hidden".

UPDATE

As noted by IlyaDoroshin the same thing can be accomplished using jQuery’s trigger():

$('#myForm').trigger("reset");

UPDATE

If you need to do more than reset the form to its default state, you should review the answers to Resetting a multi-stage form with jQuery.

Leave a Comment