checkbox disabled unable to be enabled

Discussion in 'Javascript' started by tshad, Jul 21, 2006.

  1. tshad

    tshad Guest

    I am trying to disable and enable a checkbox from javascript.

    The problem is that if the checkbox starts out as:

    <input id="Override" type="checkbox" name="Override"/>

    I can change it back and forth with no problems.
    using disabled = true or disabled = false

    If I start out as:

    <input id="Override" type="checkbox" name="Override" disabled="disabled"/>

    I can never enable it again using the above statements.

    I found a description of disabled as:
    ***********************************************************************
    disabled
    Type: boolean

    Indicates whether the checkbox is disabled or not. If this attribute is set
    to true, the checkbox is disabled. This is usually drawn with the text in
    grey. If the checkbox is disabled, it does not respond to user actions. The
    element cannot be focused and the command event will not fire. The element
    will still respond to mouse events. To enable the checkbox, leave the
    attribute out entirely as opposed to setting the value to false.
    *********************************************************************************

    How do you take the disabled attribute out using Javascript?

    Is there some other way to make this work?

    I don't have the same problem with a textbox. If it is set a
    disabled="disabled", I can still enable and disable at will.

    Thanks,

    Tom
    tshad, Jul 21, 2006
    #1
    1. Advertising

  2. tshad

    Sevinfooter Guest

    >
    > <input id="Override" type="checkbox" name="Override" disabled="disabled"/>
    >


    disabled = "false" ?????
    Sevinfooter, Jul 21, 2006
    #2
    1. Advertising

  3. tshad

    tshad Guest

    "Sevinfooter" <> wrote in message
    news:...
    > >
    >> <input id="Override" type="checkbox" name="Override"
    >> disabled="disabled"/>
    >>

    >
    > disabled = "false" ?????
    >

    Apparently, that doesn't matter.

    If I do the following in my code

    override.disabled = false;

    and then look at the page, it shows disabled="disabled".

    According to the following, it says to leave it out as opposed to setting to
    false. The problem is it already has there - how do you get rid of it?

    ***********************************************************************
    disabled
    Type: boolean

    Indicates whether the checkbox is disabled or not. If this attribute is set
    to true, the checkbox is disabled. This is usually drawn with the text in
    grey. If the checkbox is disabled, it does not respond to user actions. The
    element cannot be focused and the command event will not fire. The element
    will still respond to mouse events. To enable the checkbox, leave the
    attribute out entirely as opposed to setting the value to false.
    *********************************************************************************

    Thanks,

    Tom
    tshad, Jul 21, 2006
    #3
  4. tshad

    JustinBlat Guest

    When using the checkbox, you denote it's disabled by just saying
    "disabled" right in the tag:

    <input type="checkbox" id="myCheckBox" disabled />

    To enable or disable this by javascript, you just get a reference to
    the control, and set the disabled property to true or false:

    function SetEnabled(enabled) {
    document.getElementById('myCheckBox').disabled = !enabled;
    } // end SetChecked function

    Happy Coding!
    JustinBlat, Jul 21, 2006
    #4
  5. Sevinfooter wrote:
    >> <input id="Override" type="checkbox" name="Override"
    >> disabled="disabled"/>
    >>

    >
    > disabled = "false" ?????


    When a script assigns a value to a boolean property of a DOM object if
    that value is not of boolean type, such as the string above, the value
    will be type-converted to boolean. All non-empty strings type convert to
    boolean true, so - element.disabled = "false"; - is equivalent to -
    element.disabled = true; -.

    In XHTML mark-up the correct formulation for the attribute would be -
    disabled="disabled" -, but it is unlikely that mark-up presented here is
    actually XHTML as IE browsers do not support XHTML and so XHTML mark-up
    has no palace in current commercial web development.

    Richard.
    Richard Cornford, Jul 21, 2006
    #5
  6. tshad

    Jeremy Guest

    tshad wrote:
    > I am trying to disable and enable a checkbox from javascript.
    >
    > The problem is that if the checkbox starts out as:
    >
    > <input id="Override" type="checkbox" name="Override"/>
    >
    > I can change it back and forth with no problems.
    > using disabled = true or disabled = false
    >
    > If I start out as:
    >
    > <input id="Override" type="checkbox" name="Override" disabled="disabled"/>
    >
    > I can never enable it again using the above statements.
    >
    > I found a description of disabled as:
    > ***********************************************************************
    > disabled
    > Type: boolean
    >
    > Indicates whether the checkbox is disabled or not. If this attribute is set
    > to true, the checkbox is disabled. This is usually drawn with the text in
    > grey. If the checkbox is disabled, it does not respond to user actions. The
    > element cannot be focused and the command event will not fire. The element
    > will still respond to mouse events. To enable the checkbox, leave the
    > attribute out entirely as opposed to setting the value to false.
    > *********************************************************************************
    >
    > How do you take the disabled attribute out using Javascript?
    >
    > Is there some other way to make this work?
    >
    > I don't have the same problem with a textbox. If it is set a
    > disabled="disabled", I can still enable and disable at will.
    >
    > Thanks,
    >
    > Tom
    >
    >


    Try

    myCheckBox.removeAttribute("disabled");

    to get rid of the disabled attribute entirely. I think the fact that
    you've set it to a value (in order to be XHTML compliant) has messed
    with the DOM's mind - now, no matter what you set it to, the DOM thinks
    the "disabled" attribute is there and will always show a disabled check
    box. Removing the attribute might help.

    I also suspect that if you served up your content as
    application/xml+xhtml it would work as expected (except in IE).

    Jeremy
    Jeremy, Jul 21, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Brown
    Replies:
    1
    Views:
    4,335
    DWinter
    Aug 8, 2003
  2. Dennis Johansson
    Replies:
    1
    Views:
    491
    Dennis Johansson
    Aug 21, 2003
  3. Gabor
    Replies:
    3
    Views:
    603
    Jacob Yang [MSFT]
    Aug 26, 2003
  4. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Replies:
    2
    Views:
    6,472
    rick74
    May 27, 2008
  5. =?Utf-8?B?TWF0ZW8=?=

    Display disabled radiobutton as Enabled

    =?Utf-8?B?TWF0ZW8=?=, Jul 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    704
    =?Utf-8?B?U3JlZWppdGggUmFt?=
    Jul 12, 2005
Loading...

Share This Page