Victor
Victor

Reputation: 953

jquery checkboxlist particular element

In ASP.NET CheckBoxList is there any way to determine of a particular checkbox is checked using jquery? I need to know if "All" is checked for example, either by value or label text.

      <asp:CheckBoxList ID ="ToyotaModels" runat="server">    
               <asp:ListItem Value = "0">Corolla<asp:ListItem>
               <asp:ListItem Value = "1">Matrix<asp:ListItem>
               <asp:ListItem Value = "2">Tundra</asp:ListItem>
               <asp:ListItem Value = "3">Prius</asp:ListItem>
               <asp:ListItem Value = "4">All</asp:ListItem>
      </asp:CheckBoxList>

Upvotes: 2

Views: 3699

Answers (3)

Mark Schultheiss
Mark Schultheiss

Reputation: 34168

This should get the checked checkboxes on a click:

$('input:checked').click().each(function() {
            //process the checkbox stuff here..
 });

EDIT: based on comment

 function processChecks()
{   
    $('input:checked').each(function() 
    {
     alert($(this).val();
    });
};

Upvotes: 1

Luka
Luka

Reputation: 321

In jQuery you have .is(":checked") function that should do the trick.

Upvotes: 0

Keltex
Keltex

Reputation: 26426

You have to look at the HTML generated by ASP.NET's CheckboxList. The ID of the container for the inputs which are the check boxes is going to look like this in javascript:

<%= ToyotaModels.ClientID %>

Each checkbox input has _X appended to the ID where X is the numeric checkbox. So to find whether the first item (Corolla) is checked you can do this:

$('<%= "#" +  ToyotaModels.ClientID + "_0" %>').is(":checked")

Upvotes: 1

Related Questions