Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
-5
rated 0 times [  0] [ 5]  / answers: 1 / hits: 48613  / 12 Years ago, mon, may 21, 2012, 12:00:00

I want to make readonly checkbox. Like this:


<input type="checkbox" onclick="return false;">

I want the checkbox to look like it is disabled or grayed out.


How can I do this?


More From » jquery

 Answers
23

You need to disable the checkbox also:


<input type="checkbox" onclick="return false;" disabled="disabled">

To post the value, simply make it readonly instead:


<input type="checkbox" onclick="return false;" readonly="readonly">

You can style checkbox label and readonly inputs with CSS, e.g.: input [readonly="readonly"] {} but the browser should make the checkbox should appear greyed out when set to readonly.


Updated:


You are at the the mercy of the browser when styling checkboxes & to style them consistently across all browsers, you have to resort to images e.g.: https://archive.is/TNUH1


If you don't want to do this (and it seems like a longwinded solution), the simplest solution is to disable the checkbox so it appears correctly, and post the value as a hidden input e.g.:


<input type="checkbox" onclick="return false;" disabled="disabled">
<input type="hidden" name="checkboxval" value="111" />

[#85455] Friday, May 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cierra

Total Points: 504
Total Questions: 108
Total Answers: 109

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
;