Readonly checkbox question

Hello!
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
rj2Asked:
Who is Participating?
 
arun99907Commented:
<input type="checkbox" onclick="javascript:if(this.checked==true){this.checked=true;}else{this.checked=false}" <%=check%> >
0
 
arun99907Commented:
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

http://www.w3schools.com/tags/tag_input.asp
0
 
GwynforWebCommented:
This will do it

<input type="checkbox" onclick="this.checked=true" checked>
0
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.

 
arun99907Commented:
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";

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


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 ?
0
 
GwynforWebCommented:
<input type="checkbox" onclick="this.checked=true" checked>   Results in always checked

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

0
 
arun99907Commented:
If the Questioner is happy with this kind of answer,
 then I prefer giving/suggesting all points to GwynforWeb.
0
 
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.
0
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.