Can HTML checkboxes be set to readonly?

Electrons_Ahoy picture Electrons_Ahoy · Sep 30, 2008 · Viewed 944.3k times · Source

I thought they could be, but as I'm not putting my money where my mouth was (so to speak) setting the readonly attribute doesn't actually seem to do anything.

I'd rather not use Disabled, since I want the checked check boxes to be submitted with the rest of the form, I just don't want the client to be able to change them under certain circumstances.

Answer

Yanni picture Yanni · Aug 2, 2011

you can use this:

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

This works because returning false from the click event stops the chain of execution continuing.