Reputation: 479
I have the following function for clearing input forms:
function clearForm(form) {
$(':input', form).each(function() {
var type = this.type;
var tag = this.tagName.toLowerCase();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = "";
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
Is there any way I can stop it from clearing inputs which are 'hidden'?
Thanks in advance.
Upvotes: 1
Views: 56
Reputation: 26783
$(':input:visible').val([])
You don't need any of the code in the each function, the single line above will do it.
Upvotes: 0
Reputation: 724542
Sure, instead of
$(':input', form)
Use
$(':input:visible', form)
Upvotes: 3