Arian Arian - 4 months ago 15
jQuery Question

How to Handle Radio Button List Option change with jQuery

I hava a RadioButtonList control on my page that has multiple option.I want to handle change of its options and, according to value of selected option, do work.

This does not work:

$(document).ready(function () {
$('#RadioButtonList1').change(function () {
if ($(this).is(':checked')) {
alert("yes");
}
});
});


How I can Handle that?

thanks

Answer

You just need to bind the inputs themselves, not their group:

$(document).ready(function () {
    $('#RadioButtonList1 input').change(function () {
        // The one that fires the event is always the
        // checked one; you don't need to test for this
        alert($(this).val());
    });
});