By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,596 Members | 984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,596 IT Pros & Developers. It's quick & easy.

checkbox disabled unable to be enabled

P: n/a
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
Jul 21 '06 #1
Share this Question
Share on Google+
6 Replies

P: n/a
>
<input id="Override" type="checkbox" name="Override" disabled="disabled"/>
disabled = "false" ?????

Jul 21 '06 #2

P: n/a
"Sevinfooter" <ma**********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...

<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
Jul 21 '06 #3

P: n/a
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!

Jul 21 '06 #4

P: n/a
"tshad" <ts**********@ftsolutions.comwrote in news:QQWvg.133071
$d********@newssvr21.news.prodigy.com:
>><input id="Override" type="checkbox" name="Override"
disabled="disabled"/>
If you want to hard-code the checkbox disabled, do this:
<input id="override" type="checkbox" name="override" disabled="true" >

If you want to hard-code it enabled, do this:
<input id="override" type="checkbox" name="override" >

Either way, you can enable or disable it by doing this:
forms.<yourformname>.override.disabled=true;
forms.<yourformname>.override.disabled=false;

Tested in IE & FF.
Jul 21 '06 #5

P: n/a
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.
Jul 21 '06 #6

P: n/a
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
Jul 21 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.