Readonly checkbox question

What is the best way to make a checkbox readonly?
<INPUT TYPE="CHECKBOX" READONLY ... don't seem to work.

disabled does work, but I want it be black not gray. It's used for output only.
LVL 10
Who is Participating?
<input type="checkbox" onclick="javascript:if(this.checked==true){this.checked=true;}else{this.checked=false}" <%=check%> >
I dont think it is possible. W3C hasnt come up with that option other like Readonly on checkbox.
No other go but to use "Disabled"....

A Quick Reference of <input> tag
This will do it

<input type="checkbox" onclick="this.checked=true" checked>
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Well I dont think that will reach to the anwer.

This will always make the checkbox checked.

ReadOnly does not necessarily mean "Always Checked". It can be Unchecked also.

ReadOnly => Either Checked Always / UnChecked Always.

But this idea can be extended little to get a final solution

  String check = "";
  if(condition.. based on logic)
    check = "checked";

<script language=JavaScript>
 function callme()
    var checkVal = '<%=check%>';
         // i.e, when the page is loaded the check box is unchecked
<form name=formname>
<input type=checkbox name=checkboxname onclick="javascript:callme()" <%=check%> >

Well even this will not solve the problem. Because,

The User who is seeing the screen will actually feel for a second that he is unchecking it and still it will get checked or vice versa.

Is that what the author wants ?
<input type="checkbox" onclick="this.checked=true" checked>   Results in always checked

<input type="checkbox" onclick="this.checked=false">   Results in always unchecked

If the Questioner is happy with this kind of answer,
 then I prefer giving/suggesting all points to GwynforWeb.
rj2Author Commented:
What seems to work for me is
<input type="checkbox" onclick="javascript:if(this.checked==true){this.checked=false;}else{this.checked=true}" checked>
It look like the state is changed before ths Javascript is called.

It's easier for me to use the same Javascript for all checkboxes regardless whether it is checked or not.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.