Is There An "idiot Proof" Way To Re-enable All Fields (regardless Of There State) On A Form?
Solution 1:
The following example is the way to make sure that all fields of your current form were re-enabled. All of the elements with input, select, textarea
and checkbox
tags will become enabled as you click a button:
$(document).ready(function() {
$('#switcher').click(function() {
$('input, select').each(function() {
if ($(this).attr('disabled')) {
$(this).removeAttr('disabled');
}
});
});
});
Online example
You need to use jQuery and add it to your page by pasting the following to your page's head:
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
In this example Google CDN is being used.
Please read more about jQuery Install and jQuery Usage.
Solution 2:
In jQuery:
$(":input").prop('disabled', false);
:input
is a jQuery pseudo-selector that matches all types of form input fields. The .prop
method gets or sets properties, so this sets all the disabled
properties to false.
Solution 3:
Something along the lines of :
functionvalidate(OrderAudio) {
if(valid) {
var e = document.getElementsByTagName('input'), i;
for(i = 0; i < e.length; ++i) {
e[i].disabled = false;
}
e = document.getElementsByTagName('textarea');
for(i = 0; i < e.length; ++i) {
e[i].disabled = false;
}
}
}
Solution 4:
There is a very easy way to do this. All you have to do is put all the field items in an Array, then when the user checks the checkbox, you can make an Array loop and for every item in the Array (for(var i = 0; i < array.length; i++) if(checkBox.checked == true) {array[i].disabled = false;} else {array[i].disabled = true;}
). This will disable all items if checkbox on uncheck, and enable on check.
Here is a small diagram:
Post a Comment for "Is There An "idiot Proof" Way To Re-enable All Fields (regardless Of There State) On A Form?"