Selecting radiobuttons populated within asp.net RadioButtonList with jQuery
Hello and thanks in advance for the communal help I always find here. I have been tinkering around with what should seem a pretty straight forward task even for a jQuery newb as myself. I have a radiobuttonlist control bound to a collection:
<asp:RadioButtonList ID="radBtnLstPackageSelector" runat="server"
CssClass="PackageS">
</asp:RadioButtonList>
My form does have several other controls of the same type; Now, the challenge is to select and wire up a on Click event for every radiobut开发者_运维知识库ton from the radBtnLstPackageSelector.
I have tried several approaches such as:var results1 = $(".PackageS").children("input");
var results1 = $(".PackageS").children("input[type=radiobutton");
var results1 = $("table.PackageS > input[type=radiobutton");
with no luck... Your help would be great right now! ~m
You could also target it using the IDs of the elements ASP.NET will generate (though this isn't the best solution and may change in future versions of ASP.NET):
$(function() {
$("[id*=radBtnLstPackageSelector]:radio").click(function() {
alert( $(this).val() ); // Alerts the value of the radio button.
});
});
All IDs inside radBtnLstPackageSelector
will be in the form of
[other naming containers if there are any]_radBtnLstPackageSelector_[index of the element 1..last]
So you want a click event on each radio button in .PackageS
. Is that right?
If so, do this:
$(function() {
$(".PackageS :radio").click(function() {
alert( $(this).val() ); // Alerts the value of the radio button.
});
});
精彩评论