Skip to content

Instantly share code, notes, and snippets.

@siahr
Last active December 24, 2015 21:19
Show Gist options
  • Save siahr/6864957 to your computer and use it in GitHub Desktop.
Save siahr/6864957 to your computer and use it in GitHub Desktop.
Reset form
var resetForm = function() {
$('input, textarea, select').not('input[type="radio"], input[type="checkbox"], :hidden, :button, :submit, :reset').val('');
$('input[type="checkbox"]').removeAttr('checked');
var r = [];
var v = [];
$('input[type=\"radio\"]').each(function(){
var name = $(this).attr("name");
if ($.inArray(name, r) < 0) {
r.push(name);
v.push($(this).val());
}
});
for(var i=0; i < r.length; i++) {
$('input[name="'+r[i]+'"]').val([v[i]]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment