You need 2 jQuery functions: attr and removeAttr.
To disable a form element such as a text input or a button (with a made-up id: #elm):
$("#elm").attr("disabled", "disabled");
To enable a disabled form element:
$("#elm").removeAttr("disabled");
You need 2 jQuery functions: attr and removeAttr.
To disable a form element such as a text input or a button (with a made-up id: #elm):
$("#elm").attr("disabled", "disabled");
To enable a disabled form element:
$("#elm").removeAttr("disabled");
Comments are closed.
Ty very much!
Very useful, thanks.
The jQuery docs say to use prop() for things like disabled, checked, etc. Also the more concise way is to use their selectors engine. So to disable all form elements in a div or form parent.
$myForm.find(‘:input:not(:disabled)’).prop(‘disabled’,true);
And to enable again.
$myForm.find(‘:input:disabled’).prop(‘disabled’,false)
If you have one field to change, uou can also do it with $(‘#checkboxfield’)[0].disabled = true
@wade: native javascript is always faster than the jquery way.. in your case use: document.getElementById( “checkboxfield” ).disabled = true…
Beware of disabling form elements….. they won’t be seen in the server side……
I created a widget that can completely disable or present a read-only view of the content on your page. It disables all buttons, anchors, removes all click events, etc., and can re-enable them all back again. It even supports all jQuery UI widgets as well. I created it for an application I wrote at work. You’re free to use it.
Check it out at ( http://www.dougestep.com/dme/jquery-disabler-widget ).