How to select the listitem in RadioButtonList using jquery or javascript?

<asp:RadioButtonList ID="rdbtn" runat="server" >
                                <asp:ListItem Value="firstitem">First</asp:ListItem>
                                <asp:ListItem Value="seconditem">Second</asp:ListItem>
                            </asp:RadioButtonList>

I need to set the First listitem to be selected based on some condition. Also to deselect based on some condition.

Answers:

Answer

Consider wrapping the RadioButtonList in some element with specific id or class and using that to search the element or setting the property ClientIdMode="Static" to avoid ASP.Net from changing the id.

If all you want is the first to be selected then, find the first radiobutton and select it. I don't know what is your condition that you are speaking of.

jQuery:

$(function() {
   $("#rdbtn :radio:first").prop("checked", true);
});

Select with specific value:

   $(function() {
       $("#rdbtn :radio[value='1']").prop("checked", true);
    });

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.