I am trying using several asp.net checkboxes on a page, disabling them accordingly.
<asp:CheckBox ID='chkMenuItem' runat='server' CssClass='HiddenText' Text='Test' onclick='<%#String.Format("checkChild({0});", Eval("id")) %>' />
on javascript, I am using the following code
function checkChild(id) {
for (i = 0; i < $("input[id*=hdnParentMenuItemID]").length; i++) {
if ($('input[id*=hdnParentMenuItemID]')[i].value.split(':')[0] == id) {
var childID = $('input[id*=hdnParentMenuItemID]')[i].value.split(':')[1];
if ($("#" + childID).attr("disabled"))
//$("#" + childID).attr('disabled', '');
$("#" + childID).removeAttr("disabled");
else
$("#" + childID).attr('disabled', true);
}
}
}
Now is the checkboxes are disabled once the page is loaded, the removeAttr section doesn't work. I tried to step through the debugger and the logic works perfectly fine. If the checkboxes aren't disabled on page load, the code works fine. I tried replacing disabled 'attributes' with 'checked' to see if the other attributes work fine and it works perfectly fine. I tried
$("#" + childID).attr('disabled', '');
but it didnt work either.
Note: It works perfect on FF and Chrome but doesnt work in IE.
Thanks,
I had similar problems enabling an <asp:CheckBox />
in Internet Explorer using jQuery. The following code worked perfectly fine in FireFox.
$('myCheckBox').removeAttr('disabled');
However, it failed to work properly in IE.
An <asp:CheckBox />
is rendered as a <span />
with an <input />
and a <label />
tag. When the checkbox is disabled both the span and the input tags are decorated with the disabled attribute. To get the expected behavior I used to the following code:
$('myCheckBox').removeAttr('disabled');
$('myCheckBox').closest('span').removeAttr('disabled');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With