I have a form where I have to post form values to my action class. In this form I have a checkbox that needs to be readonly. I tried setting disabled="true"
but that doesn't work when posting to the action class.
So please advice??
You can easily do this by css. HTML :
<form id="aform" name="aform" method="POST">
<input name="chkBox_1" type="checkbox" checked value="1" readonly />
<br/>
<input name="chkBox_2" type="checkbox" value="1" readonly />
<br/>
<input id="submitBttn" type="button" value="Submit">
</form>
CSS :
input[type="checkbox"][readonly] {
pointer-events: none;
}
This doesn't prevent ticking of the checkbox via the keyboard (tab to the checkbox, and hit spacebar).
For preventing ticking of the checkbox via the keyboard, please use Patrick's answer at stackoverflow.com/a/12267350/1091926
If the checkbox is followed by a label (which is also clickable), we may also add this CSS: input[type="checkbox"][readonly] + label { pointer-events: none; }
@jtheletter, just need to add
tab-index="-1"