I have a form that pop up inside a layer, and I need to make everything inside that form read only regarding what type of input it is. Anyway to do so?
Read-only is not the same as disabled.
Tim Down
2010-08-02 11:12:32
Yes, you are correct. The original question has 'disable' in the title. Either way, it's trivially easy.
Victor
2010-08-02 19:55:17
A:
$("#formid input, #formid select").attr('disabled',true);
or to make it read-only:
$("#formid input, #formid select").attr('readonly',true);
Māris Kiseļovs
2010-08-02 10:45:02
+4
A:
You can use the :input
selector, and do this:
$("#myForm :input").attr('readonly', true);
:input
selects all <input>
, <select>
, <textarea>
and <button>
elements. Also the attribute is "readonly", if you "disable" the elements they won't be posted to the server, so choose which property you want based on that.
Nick Craver
2010-08-02 10:45:40
+2
A:
This is quite simple in plain JavaScript and will work efficiently in all browsers that support read-only form inputs (which is pretty much all browsers released in the last decade):
var form = document.getElementById("your_form_id");
var elements = form.elements;
for (var i = 0, len = elements.length; i < len; ++i) {
elements[i].readOnly = true;
}
Tim Down
2010-08-02 11:06:53