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?
To disable all form elements inside 'target', use the :input selector which matches all input, textarea, select and button elements.
To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.
Answer: To disable all input elements within div use the following code: $('#message :input'). attr('disabled', true);
$( "#x" ).prop( "disabled", false );
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;
}
With HTML5 it's possible to disable all inputs contained using the <fieldset disabled />
attribute.
disabled:
If this Boolean attribute is set, the form controls that are its descendants, except descendants of its first optional element, are disabled, i.e., not editable. They won't received any browsing events, like mouse clicks or focus-related ones. Often browsers display such controls as gray.
Reference: MDC: fieldset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With