tags:

views:

164

answers:

3

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>
A: 

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")
Keltex
A: 

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

Luka
A: 

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();
    });
};
Mark Schultheiss
Thanks for reply. This is not a click event handler though. I was thinking to do something like this, in the 'input:checked' loop find out if particular element is one of the checked. Was just wondering if there is more elegant way of doing it, perhaps in a single selector?
Victor
so probably just take out the .click() from that (inside whatever you have that instigates the behavior you need) $('input:checked').each(function() { //process the checkbox stuff here.. });
Mark Schultheiss
Thanks. This worked: $('#<%= ToyotaModels.ClientID %> input:checked').each(function().
Victor