What is the nicest way to disable all form controls on a web page? I have read that this cannot be done via CSS but this would be my preferred option if possible. I also have access to jQuery if that makes life easier.
Asked
Active
Viewed 2.0k times
16
-
Possible dupe http://stackoverflow.com/questions/2310816/disabling-all-form-elements-in-selected-div-edited and http://stackoverflow.com/search?q=disable+form – zaf Apr 26 '10 at 08:34
-
This has nothing to do with presentation, so CSS would be the wrong tool. (It also sounds like you may be trying to get things that look like form controls, but never intend to get user input using them, if so, then form controls are the wrong tool too.) – Quentin Apr 26 '10 at 08:36
-
@Chris - ideally the update to your question should be asked separately. – karim79 Apr 26 '10 at 08:40
3 Answers
2
@karim79 is right with his CSS selectors, but convention calls for the jquery .prop() function (see docs here).
So I suggest...
$("form :input").prop("disabled",true);
Here is a similar situation where the .prop() function is appropriate.
Hope this helps!

Community
- 1
- 1

Freestyle076
- 1,548
- 19
- 36
1
U can disable all input type areas using below one.
jQuery 1.5 and below
any text box - $("input[type=text]").attr('disabled', true);
any radio button - $("input[type=radio]").attr('disabled', true);
any checkbox - $("input[type=checkbox]").attr('disabled',true);
jQuery 1.6+
any text box - $("input[type=text]").prop('disabled', true);
any radio button - $("input[type=radio]").prop('disabled', true);
any checkbox - $("input[type=checkbox]").prop('disabled',true);

Kasun Gamage
- 346
- 2
- 3
- 18