I have a checkbox and radiobuttonlist defined as follows:
<asp:CheckBox id="chkChange" runat="server" text="Enable" />
<br />
<asp:RadioButtonList id="rblConsole" runat="server" cssclass="console">
<asp:ListItem text="XBox 360" value="xbox" />
<asp:ListItem text="Playstation 3" value="playstation" />
</asp:RadioButtonList>
These controls are in a content page with a master page so the actual html rendered is:
<table id="ctl00_ContentPlaceHolder1_rblConsole" class="console" border="0">
<tr>
<td><input id="ctl00_ContentPlaceHolder1_rblConsole_0" type="radio" name="ctl00$ContentPlaceHolder1$rblConsole" value="xbox" /><label for="ctl00_ContentPlaceHolder1_rblConsole_0">XBox 360</label>
</td>
</tr>
<tr>
<td><input id="ctl00_ContentPlaceHolder1_rblConsole_1" type="radio" name="ctl00$ContentPlaceHolder1$rblConsole" value="playstation" /><label for="ctl00_ContentPlaceHolder1_rblConsole_1">Playstation 3</label>
</td>
</tr>
</table>
On the javascript onclick on the checkbox I want to disable the radio buttons in the rblConsole radiobutton list.
I'm trying to get at the radio buttons via the jQuery endswith selector:
function ToggleEnabled() {
var isChecked = $("*[id$='chkChange']").is(":checked");
if (isChecked) {
$("*[name$='rblConsole'").removeAttr("disabled");
} else {
$("*[name$='rblConsole'").attr("disabled", "disabled");
}
}
So, how to disable these via jQuery?
I have a checkbox and radiobuttonlist defined as follows:
<asp:CheckBox id="chkChange" runat="server" text="Enable" />
<br />
<asp:RadioButtonList id="rblConsole" runat="server" cssclass="console">
<asp:ListItem text="XBox 360" value="xbox" />
<asp:ListItem text="Playstation 3" value="playstation" />
</asp:RadioButtonList>
These controls are in a content page with a master page so the actual html rendered is:
<table id="ctl00_ContentPlaceHolder1_rblConsole" class="console" border="0">
<tr>
<td><input id="ctl00_ContentPlaceHolder1_rblConsole_0" type="radio" name="ctl00$ContentPlaceHolder1$rblConsole" value="xbox" /><label for="ctl00_ContentPlaceHolder1_rblConsole_0">XBox 360</label>
</td>
</tr>
<tr>
<td><input id="ctl00_ContentPlaceHolder1_rblConsole_1" type="radio" name="ctl00$ContentPlaceHolder1$rblConsole" value="playstation" /><label for="ctl00_ContentPlaceHolder1_rblConsole_1">Playstation 3</label>
</td>
</tr>
</table>
On the javascript onclick on the checkbox I want to disable the radio buttons in the rblConsole radiobutton list.
I'm trying to get at the radio buttons via the jQuery endswith selector:
function ToggleEnabled() {
var isChecked = $("*[id$='chkChange']").is(":checked");
if (isChecked) {
$("*[name$='rblConsole'").removeAttr("disabled");
} else {
$("*[name$='rblConsole'").attr("disabled", "disabled");
}
}
So, how to disable these via jQuery?
Share Improve this question edited Apr 25, 2009 at 13:26 John Saunders 162k26 gold badges251 silver badges402 bronze badges asked Apr 24, 2009 at 22:26 Ciaran O'NeillCiaran O'Neill 2,6347 gold badges36 silver badges42 bronze badges4 Answers
Reset to default 3first, remove the apostrophy in the attribute selector
function ToggleEnabled() {
var isChecked = $("*[id$='chkChange']").is(":checked");
if (isChecked) {
$("*[name$=rblConsole").removeAttr("disabled");
} else {
$("*[name$=rblConsole").attr("disabled", "disabled");
}
}
second, it is better tu use the ClientID property of the controls to get the elements ids:
function ToggleEnabled() {
var isChecked = $("#<%=chkChange.ClientID %>").is(":checked");
if (isChecked) {
$("#<%=rblConsole.ClientID %>").removeAttr("disabled");
} else {
$("#<%=rblConsole.ClientID %>").attr("disabled", "disabled");
}
}
I was missing the closing square bracket in the selector. It should be:
$("*[name$='rblConsole']").attr("disabled", "disabled");
Doh! My bad.
Below code works for me,
For Disable
$("table[id$=<%= rblConsole.ClientID %>] input").attr("disabled", "disabled");
For Enable
$("table[id$=<%= rblConsole.ClientID %>] input").removeAttr("disabled");
Please check this:
$("input[type=radio][value=EIN]").prop("disabled", true);