Hi guys,
Working on one of my web projects recently I came accross a need for presenting some readonly data as part of the user input form. The readonly property of the input tags seem to work as expected for other types of input control, but not for the checkbox.

Sample code:

<input id="chkExempt" type="checkbox" readonly="readonly" /> Exemption

The result is a checkbox that is "greyed out" in appearance but still responds as normal to user interaction (ie: clicking checks/unchecks). I also tried this with readonly="true" as seems to be the Microsoft way of doing things, but the results were the same.

I can of course set the checkbox to be disabled, but then it no longer is pushed back to the server as part of the form post, which I needed.

Does anyone know why this doesn't work? or an alternate way of achieving the desired outcome? (preferably avoiding javascript)


Thanks, that will do what I need.

I still do wonder if there is any way of making the readonly property work without javascript? Or is this feature just not implemented in the HTML standard or something?

<input type="checkbox" disabled="disabled" checked="checked">

readonly is indeed not supported. So if you need it to POST, include a hidden tag as well.

Hmm.. seems strange to me that the property is not supported, but eh.

Both good work-arounds, thanks for the advice guys.

i think best solution is

<input type="checkbox" onclick="return false" onkeydown="return false" />