CodeCopy

September 11, 2012

asp.net checkbox check/uncheck all with JQuery

Filed under: asp.net,JQuery — sterndorff @ 09:29

html:

<asp:CheckBox CssClass="ChooseAll" Text="Choose all" runat="server" /><br />
<asp:CheckBox CssClass="CheckBoxItem" Text="Checkbox 1" runat="server" /><br />
<asp:CheckBox CssClass="CheckBoxItem" Text="Checkbox 2" runat="server" /><br />
<asp:CheckBox CssClass="CheckBoxItem" Text="Checkbox 3" runat="server" /><br />

jquery:

$(document).ready(function () {
     $(".ChooseAll input:checkbox").change(function ()
     {
         var checked = $(this).attr('checked') || false;
         $(".CheckBoxItem input:checkbox").attr('checked', checked);
     });

     $(".CheckBoxItem input:checkbox").change(function ()
     {
         var checked = ($(".CheckBoxItem input:checked").length == $(".CheckBoxItem input:checkbox").length);
         $(".ChooseAll input:checkbox").attr('checked', checked);
     });
});

1 Comment »

  1. Everyone loves what you guys tend to be up too. This sort of
    clever work and coverage! Keep up the superb works guys I’ve incorporated you
    guys to my personal blogroll.

    Comment by Portland SEO Pros — August 10, 2014 @ 18:05 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.