Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10088
  • Last Modified:

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.
0
rj2
Asked:
rj2
  • 4
  • 2
2 Solutions
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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:
<input type="checkbox" onclick="javascript:if(this.checked==true){this.checked=true;}else{this.checked=false}" <%=check%> >
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now