I’m attempting to disable a radio button from an asp RadioButtonList using JavaScript. Here is what I have:
<asp:RadioButton ID="rbPlanner" runat="server" onclick="deselectRadioListItem('P');" />
which calls this client JavaScript onClick…
function deselectRadioListItem(radioValue) {
var clientID = ('<%= rblSummaryOptions.ClientID %>');
for (i = 0; i < '<%= rblSummaryOptions.Items.Count %>'; i++) {
if (document.getElementById(clientID + "_" + i.toString()).value == radioValue) {
(clientID + "_" + i.toString()).disabled === true;
}
else
{
(clientID + "_" + i.toString()).disabled === false;
}
}
}
Everything appears to be working correctly (fires, iterates, if-statements work) however, the radiobutton control is not becoming disabled, even though the logic is hit. What am I missing? Help is much appreciated!
The
===operator is used for comparison. You need to use=.Or cleaned up a tiny bit:
Additional Information: Check out Comparison Operators on MDN.