Clear all forms on page load

Tural Ali picture Tural Ali · Nov 18, 2011 · Viewed 21.7k times · Source

I want to clear all forms on page load. I tried to use this function on domready, but it doesn't help. I'm new to JavaScript. Is there anything wrong with this function?

   $(':input', form)
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');

Answer

Doug Owings picture Doug Owings · Nov 18, 2011

You can try using the plain javascript reset method on a form

$('form').each(function() { this.reset() });

This should reset each form to its default state.

To re-enable all checkboxes, you can try:

$(':checkbox').prop('disabled', false);