how can I disable everything inside a form using javascript/jquery?

Luci picture Luci · Aug 2, 2010 · Viewed 80.1k times · Source

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?

Answer

Tim Down picture Tim Down · Aug 2, 2010

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;
}