P_R
P_R

Reputation: 488

Asp.net Select RadioButtonList using JQUERY

Hi I have a radio button list

<asp:RadioButtonList ID="lista_ragionevolezza" runat="server" 
 DataSourceID="EntityDataSource_ragionevolezza" 
 DataTextField="descrizione" DataValueField="id" 
 SelectedValue='<%# Bind("id_ragionevolezza") %>' 
 class="radioButtonScegli" />

and I want to select this in a Javascript function using JQuery for clearing a selection

var rbList=$("." + "radioButtonScegli");

using this class selector, but the code didn't work. What is the correct way to select this object? Thanks

Upvotes: 0

Views: 1892

Answers (4)

Marco
Marco

Reputation: 23927

I suggest to not use the class selector, but the Client Id, because your javascript variable would change if you have more the 1 object which has the class radioButtonScegli.

Try selecting it this way:

var rbList = $('#<%=lista_ragionevolezza.ClientID%>')

This way rbList will only contain this one RadiobuttonList. And since this is an element containing 1 to n checkboxes, you need to iterate over each item to uncheck it:

rbList.each(function (i, chkbox){
    if($(chkbox).is(":checked")) {
        $(chkbox).removeAttr("checked");
    }
});

Upvotes: 0

By ID

var radiolist= $('input:radio[id$="lista_ragionevolezza"]');

By class

var radiolist= $('input:radio[class="radioButtonScegli"]');

or just $('.radioButtonScegli')

to make checked/unchecked you can use either attr or prop

$('.radioButtonScegli').find(':radio').attr('checked',false);

$('.radioButtonScegli').find(':radio').prop('checked',false);

Upvotes: 0

Rudy
Rudy

Reputation: 2353

The class is added to a container in which .Net is placing those inputs. Something like this should work: $(".radioButtonScegli").find(':radio');

For clearing selection:

$('.radioButtonScegli').find(':radio').prop('checked',false);'

Upvotes: 2

Dean.DePue
Dean.DePue

Reputation: 1013

You have to use the ID of object:

var rblist = $("#lista_regionevolezza");

Upvotes: -1

Related Questions