Connecting Tech Pros Worldwide Forums | Help | Site Map

checkbox disabled unable to be enabled

tshad
Guest
 
Posts: n/a
#1: Jul 21 '06
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



Sevinfooter
Guest
 
Posts: n/a
#2: Jul 21 '06

re: checkbox disabled unable to be enabled


>
Quote:
<input id="Override" type="checkbox" name="Override" disabled="disabled"/>
>
disabled = "false" ?????

tshad
Guest
 
Posts: n/a
#3: Jul 21 '06

re: checkbox disabled unable to be enabled


"Sevinfooter" <mark.e.davis@gmail.comwrote in message
news:1153442973.351336.66980@b28g2000cwb.googlegro ups.com...
Quote:
Quote:

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


JustinBlat
Guest
 
Posts: n/a
#4: Jul 21 '06

re: checkbox disabled unable to be enabled


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!

Jim Land
Guest
 
Posts: n/a
#5: Jul 21 '06

re: checkbox disabled unable to be enabled


"tshad" <tscheiderich@ftsolutions.comwrote in news:QQWvg.133071
$dW3.57216@newssvr21.news.prodigy.com:
Quote:
Quote:
Quote:
>><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.


Richard Cornford
Guest
 
Posts: n/a
#6: Jul 21 '06

re: checkbox disabled unable to be enabled


Sevinfooter wrote:
Quote:
Quote:
><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.


Jeremy
Guest
 
Posts: n/a
#7: Jul 21 '06

re: checkbox disabled unable to be enabled


tshad wrote:
Quote:
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
Closed Thread