Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear radiobutton list selection using jquery

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>
like image 761
nav100 Avatar asked Sep 18 '12 18:09

nav100


3 Answers

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");
    }
});
like image 100
Jupaol Avatar answered Oct 06 '22 08:10

Jupaol


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);     
}
like image 39
Musa Avatar answered Oct 06 '22 08:10

Musa


You should be using prop(). Also, each() to iterate:

$('.checkboxlistid9').each(function (index, elem){
    $(elem).prop('checked',false);
})
like image 37
Adriano Carneiro Avatar answered Oct 06 '22 09:10

Adriano Carneiro