Need A Javascript To Enable Or Disable The Check Box
Hi all i am having two check box controls in my gridview what i need is if i checked a check box the other should be get enabled and if i uncheck it should get disable is there any
Solution 1:
Basically, what you want is something like this:
functioncheckboxClick(checked) {
document.getElementById('childCheckbox').disabled = !checked;
}
<inputtype="checkbox" onclick="checkboxClick(this.checked);" />
<inputtype="checkbox" id="childCheckbox" />
Now, if they're ASP.NET controls, <asp:CheckBox />
, you will probably want to edit checkboxClick
so that it also takes the ClientID of the checkbox to enable/disable.
<asp:CheckBox runat="server"id="cb1" />
<asp:CheckBox runat="server"id="cb2" />
var cb2 = FindControl("cb2");
((CheckBox) FindControl("cb1")).OnClientClick = "checkboxClick(this.checked, '" + cb2.ClientID + "');";
EDIT
Accommodating further requirements as per comments:
function checkboxClick(checked, boxId) {
var childCheckbox = document.getElementById(boxId);
childCheckbox.disabled = !checked;
if(childCheckbox.disabled) //uncheck when disabled
childCheckbox.checked = false;
}
<asp:CheckBoxrunat="server"id="cb1" /><asp:CheckBoxrunat="server"id="cb2"Enabled="false" /><!-- disable on load -->
Post a Comment for "Need A Javascript To Enable Or Disable The Check Box"