Readonly checkbox question

Posted on 2005-05-10
Last Modified: 2012-05-05
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.
Question by:rj2
    LVL 3

    Expert Comment

    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
    LVL 31

    Expert Comment

    This will do it

    <input type="checkbox" onclick="this.checked=true" checked>
    LVL 3

    Expert Comment

    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 ?
    LVL 31

    Assisted Solution

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

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

    LVL 3

    Accepted Solution

    <input type="checkbox" onclick="javascript:if(this.checked==true){this.checked=true;}else{this.checked=false}" <%=check%> >
    LVL 3

    Expert Comment

    If the Questioner is happy with this kind of answer,
     then I prefer giving/suggesting all points to GwynforWeb.
    LVL 10

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now