I want to set the drop down as readonly.
For that I user the code readonly="readonly"
.But its not working in asp.netmvc4.How can I solve this problem?Please help
Asked
Active
Viewed 3.5k times
6

Nithin Viswanathan
- 3,245
- 7
- 39
- 84
-
@Agent1 [http://stackoverflow.com/questions/8100351/how-to-make-a-dropdown-readonly-using-jquery](http://stackoverflow.com/questions/8100351/how-to-make-a-dropdown-readonly-using-jquery) Here you can find the answer. – Praveen May 23 '13 at 12:09
4 Answers
11
You can do like this
Make other options disabled except the current one.
$('option:not(:selected)').attr('disabled', true);

Dhaval Marthak
- 17,246
- 6
- 46
- 68
-
1very useful tip, specially when you have to post your values from protected fields without any hidden fields $(function () { $("select[readonly='readonly'] option:not(:selected)").attr('disabled', true); }); – Jerzy Gebler Sep 16 '14 at 13:07
4
-
@PSR-I don't want disabled.If it is disabled i can't take the value from it – Nithin Viswanathan May 23 '13 at 12:05
-
1
-
1@Agent1 Well what did you mean then? Drop downs are always read-only.. – dsgriffin May 23 '13 at 12:06
-
0
It can be done via jquery. It saves you from browser compatibility issues too. jQuery:
$('#yourselectid').attr("disabled", true);

edd
- 1,356
- 7
- 12
0
Unfortunately the select element doesn't accept readonly, W3 spec is here for reference.
As others have suggested, your best bet would be to use the disabled 'disabled' attribute instead.

johnkavanagh
- 4,614
- 2
- 25
- 37