Question

I need to set the default text of radiobutton as Male in the function fnclear()

<asp:RadioButtonList ID="rblGender" runat="server" RepeatDirection="horizontal">
<asp:ListItem Selected="True" Value="M">Male</asp:ListItem>
<asp:ListItem Value="F">Female</asp:ListItem>
</asp:RadioButtonList>

<script type="text/javascript">
function fnClear() {
$('#<%= txtName.ClientID %>').val('');
$('#<%= rblGender.ClientID %>').val('M');
}
</script>
Was it helpful?

Solution

Use:

$('input[id*=rblGender][type=radio][value="M"]')prop('checked', true);

or

 $('#<%=rblGender.ClientID %>').find("input[value='M']").attr("checked", "checked");

OTHER TIPS

You can try this code to set default check value 'Male'

$('#<%=rblGender.ClientID %> [type=radio][value=M]').prop('checked', true);

Set radio button by text

$("input:radio").each(function () {
                var idVal = $(this).attr("id");
                if ($("label[for='" + idVal + "']").text() == "Male") {
                    $(this).prop("checked", true);
                }
            });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top