How to exclude read only fields using :input in jquery?

Posted by melaos on Stack Overflow See other posts from Stack Overflow or by melaos
Published on 2010-04-11T13:02:06Z Indexed on 2010/04/11 13:13 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

hi guys, thus far i've only been using some basic jquery selectors and functions. but i'm looking at this clear form function and i can't figure out how to add it so i can remove hidden inputs and readonly input from getting cleared.

can anybody help? thanks.

function clearForm(form) {
  // iterate over all of the inputs for the form
  // element that was passed in
  $(':input', form).each(function() {
 var type = this.type;
 var tag = this.tagName.toLowerCase(); // normalize case
 // it's ok to reset the value attr of text inputs,
 // password inputs, and textareas
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = "";
 // checkboxes and radios need to have their checked state cleared
 // but should *not* have their 'value' changed
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 // select elements need to have their 'selectedIndex' property set to -1
 // (this works for both single and multiple select elements)
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about clear