I would like to clear Radiobutton list selection after user enters the text in the TextBox. I tried the following code but it doesn't seem to be working and it doesn't show any error. Please let me know if there are any suggestions.
function ClearRadioButtonList() {
var checkboxlistid9 = "#<%= rblLst.ClientID %>";
$('.checkboxlistid9').attr('checked',false);
}
<telerik:RadMaskedTextBox ID="txtCode" runat="server" Mask="###-##-####" SelectionOnFocus="CaretToBeginning">
<ClientEvents OnBlur="ClearRadioButtonList" />
</telerik:RadMaskedTextBox>
<asp:RadioButtonList ID="rblLst" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1">Unknown</asp:ListItem>
<asp:ListItem Value="2">Not Applicable</asp:ListItem>
</asp:RadioButtonList>
Instead of:
$('.checkboxlistid9').attr('checked',false);
Try:
$('.checkboxlistid9').removeAttr('checked');
Additionally I think your jQuery selector is wrong
$('.checkboxlistid9')
I don't see a class checkboxlistid9
on your asp:RadioButtonList
Change the query selector to:
$("table[id$=rblLst] input:radio:checked").removeAttr("checked");
Or
$("table[id$=rblLst] input:radio").each(function (i, x){
if($(x).is(":checked")){
$(x).removeAttr("checked");
}
});
The radio buttons will be descendants of the element that represents the RadioButtonList
, you can select them with #<%= rblLst.ClientID %> input[type=radio]
and use .prop()
to remove the checked property.
function ClearRadioButtonList() {
$("#<%= rblLst.ClientID %> input[type=radio]").prop('checked',false);
}
You should be using prop()
. Also, each()
to iterate:
$('.checkboxlistid9').each(function (index, elem){
$(elem).prop('checked',false);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With