Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
117 Points
42 Posts
May 04, 2012 08:48 AM|LINK
Hi,
I wrote this code its woking fine with enabling the radio buttonlist but has some issue in disable.
The disable woks fine if ter is only radiobutton.
<head runat="server"> <title></title> <script type="text/ecmascript" language="javascript"> function rblSelectedValue(rbl,rblY,rblN) { var txt, rdO; rdO = document.getElementsByName(rbl); //alert(rdO.length); for (var i = 0; i < rdO.length; i++) { if (rdO[i].checked) { txt = rdO[i].parentNode.getElementsByTagName('label')[0].innerHTML; } } if (txt == "YES") { EnableChild(document.getElementById(rblY)); // DisableChild(document.getElementById(rblN)); } else { EnableChild(document.getElementById(rblN)); // DisableChild(document.getElementById(rblY)); } } function EnableChild(control) { var children = control.childNodes; try { control.removeAttribute('disabled') } catch (ex) { } for (var j = 0; j < children.length; j++) { EnableChild(children[j]); } } // function DisableChild(control1) { // var children1 = control1.childNodes; // // try {children1.attr("disabled", true); } // catch (ex) { } // for (var j = 0; j < children1.length; j++) { // DisableChild(children1[j]); // } // } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:RadioButtonList ID="rbtnMain" runat="server" OnClick="rblSelectedValue('rbtnMain','rbtnMainYes','rbtnMainNo')"> <asp:ListItem Text="YES" Value="1"></asp:ListItem> <asp:ListItem Text="NO" Value="0"></asp:ListItem> </asp:RadioButtonList> <br /> <br /> YES -- Options <asp:RadioButtonList ID="rbtnMainYes" runat="server" Enabled="false" > <asp:ListItem Text="Options Yes -1" Value="1"></asp:ListItem> <asp:ListItem Text="Options Yes -2" Value="2"></asp:ListItem> <asp:ListItem Text="Options Yes -3" Value="3"></asp:ListItem> </asp:RadioButtonList> <br /><br /> NO -- Options <asp:RadioButtonList ID="rbtnMainNo" runat="server" Enabled="false"> <asp:ListItem Text="Options No -1" Value="1"></asp:ListItem> <asp:ListItem Text="Options No -2" Value="2"></asp:ListItem> <asp:ListItem Text="Options No -3" Value="3"></asp:ListItem> </asp:RadioButtonList> <br /><br /> <asp:Button ID="btnSave" runat="server" Text="Save" /> </div> </form> </body> </html>
shari.aravin...
Member
117 Points
42 Posts
Re: Enable Disable RadioButtonList with another RadiobButtonList Selection ASP.NET
May 04, 2012 08:48 AM|LINK
Hi,
I wrote this code its woking fine with enabling the radio buttonlist but has some issue in disable.
The disable woks fine if ter is only radiobutton.
<head runat="server">
<title></title>
<script type="text/ecmascript" language="javascript">
function rblSelectedValue(rbl,rblY,rblN) {
var txt, rdO;
rdO = document.getElementsByName(rbl);
//alert(rdO.length);
for (var i = 0; i < rdO.length; i++) {
if (rdO[i].checked) {
txt = rdO[i].parentNode.getElementsByTagName('label')[0].innerHTML;
}
}
if (txt == "YES") {
EnableChild(document.getElementById(rblY));
// DisableChild(document.getElementById(rblN));
}
else {
EnableChild(document.getElementById(rblN));
// DisableChild(document.getElementById(rblY));
}
}
function EnableChild(control) {
var children = control.childNodes;
try { control.removeAttribute('disabled') }
catch (ex) { }
for (var j = 0; j < children.length; j++) {
EnableChild(children[j]);
}
}
// function DisableChild(control1) {
// var children1 = control1.childNodes;
//
// try {children1.attr("disabled", true); }
// catch (ex) { }
// for (var j = 0; j < children1.length; j++) {
// DisableChild(children1[j]);
// }
// }
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rbtnMain" runat="server" OnClick="rblSelectedValue('rbtnMain','rbtnMainYes','rbtnMainNo')">
<asp:ListItem Text="YES" Value="1"></asp:ListItem>
<asp:ListItem Text="NO" Value="0"></asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
YES -- Options
<asp:RadioButtonList ID="rbtnMainYes" runat="server" Enabled="false" >
<asp:ListItem Text="Options Yes -1" Value="1"></asp:ListItem>
<asp:ListItem Text="Options Yes -2" Value="2"></asp:ListItem>
<asp:ListItem Text="Options Yes -3" Value="3"></asp:ListItem>
</asp:RadioButtonList>
<br /><br />
NO -- Options
<asp:RadioButtonList ID="rbtnMainNo" runat="server" Enabled="false">
<asp:ListItem Text="Options No -1" Value="1"></asp:ListItem>
<asp:ListItem Text="Options No -2" Value="2"></asp:ListItem>
<asp:ListItem Text="Options No -3" Value="3"></asp:ListItem>
</asp:RadioButtonList>
<br /><br />
<asp:Button ID="btnSave" runat="server" Text="Save" />
</div>
</form>
</body>
</html>
Keep Smiling :)
Thanks,
Shari