Has anyone ever done or know of a way to make an option from a checkbox form field read only? As an example below, Email is automatically selected and I also want it to be read only so the requester is not able to uncheck it.
Has anyone ever done or know of a way to make an option from a checkbox form field read only? As an example below, Email is automatically selected and I also want it to be read only so the requester is not able to uncheck it.
Readonly does not work with checkboxes because "readonly" applies to the value and with checkboxes your actually changing the state and not the value.
The only option to prevent users from unchecking it is to disable it after it has been automatically checked. However, make sure you test it because a disabled field may not be captured on submission.
If the value is not captured because it is disabled, you may need an additional script that re-enables it right before submission.
Thanks Jason for replying. As I was trying different things, I found the code below actually did what I wanted. It's the same code that I used for making a field read only, but instead of putting in the #q.. value, i used the field id. I'm still testing, but it seems to work.
$('Field53-0 input').attr("readonly", "true");
What is it actually doing?
I'm a bit confused as to why that would work because the Field53-0 identifier would be attached to the input itself, and the # is needed to indicate it is an id attribute, so that code shouldn't be finding any matches.
You can apply the readonly attribute to checkboxes, but it doesn't actually do anything in browsers because of how HTML works.
Before I added the piece of code, the Email option was automatically checked, but the user was able to uncheck it. I was still able to select other options without any issues. After I added the code, the Email option was still automatically checked, but the user is not able to uncheck it. Other options are still able to be selected.