473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

checkbox disabled unable to be enabled

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
6 23818
>
<input id="Override" type="checkbox" name="Override" disabled="disabled"/>
disabled = "false" ?????

Jul 21 '06 #2
"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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Wake | last post by:
I have two radio buttons and two checkboxes in a form. I'm trying to write some code so that when a radio button is selected, its corresponding checkbox is disabled. My code looks like this: ...
0
by: Dave | last post by:
How do I programatically read the enabled or disabled status of accounts? Have read the msdn article: http://msdn.microsoft.com/library/default.asp? url=/library/en-...
5
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add...
3
by: Assimalyst | last post by:
Hi I am attempting to enable/disable webform controls depending on whether a checkbox is checked or not. I have an event handler for when the checkbox checked is changed ...
4
by: Joseph Geretz | last post by:
I'm trying to convert my DIME Web Service (WSE 2.0) to use MTOM (WSE 3.0). All the literature I'm reading specifies that I'll need to check both: Enable this project for Web Services Enhancements...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
How can I make a checkbox control ReadOnly - can't check or uncheck without having to set the Enabled Property to False? VB2005 I looked at the property sheet for the Checkbox control but did...
8
by: Sid | last post by:
I hope someone could help me with this. I am trying to setup a criteria to decide when to allow/not allow user to click on the check box. logically it looks simple but I am not able to...
1
nev
by: nev | last post by:
when i do... dgv.enabled = false dgv gets disabled as in you are unable to use the control. but it looks enabled because its appearance is still the same. Unlike a textbox which becomes...
2
by: CreativeMind | last post by:
hi i have following code but problem is that when i debug both checkboxes have disabled property always false whether it is checked or unchecked..thx for help. function checkFinance(){ var...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.