[jQuery] How to Clear, Reset, and Empty Form Values

Tadashi Shigeoka ·  Thu, August 8, 2013

Here’s how to clear form values with jQuery.

jQuery
var clearAllFormValues = function() {
  $('input,textarea')
    .not('input[type=\\"radio\\"],input[type=\\"checkbox\\"],:hidden, :button, :submit,:reset')
    .val('');
  $('input[type=\\"radio\\"], input[type=\\"checkbox\\"],select')
    .removeAttr('checked')
    .removeAttr('selected');
}
// Clear form values within div#modal-area
var clearModalAreaFormValues = function() {
  $('#modal-area')
    .find('input,textarea')
    .not('input[type=\\"radio\\"],input[type=\\"checkbox\\"],:hidden, :button, :submit,:reset')
    .val('');
  $('#modal-area')
    .find('input[type=\\"radio\\"], input[type=\\"checkbox\\"],select')
    .removeAttr('checked')
    .removeAttr('selected');
}

That’s all from the Gemba.