checkbox disabled unable to be enabled

T

tshad

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
 
T

tshad

Sevinfooter said:
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
 
J

JustinBlat

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

Richard Cornford

Sevinfooter said:
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.
 
J

Jeremy

tshad said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top