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 should also read:
- jQuery: Check / uncheck form checkbox and radio
- CSS: Styling File Upload / Select Input Control <input type="file" … />
- jQuery: How to check if an element has a particular class
- JavaScript: How to set focus to form elements?
- jQuery: Protecting or hiding variables / functions in a specific local scope


Facebook
Twitter
Google Plus
{ 5 comments… read them below or add one }
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…