3

HTML

 <div>
    <asp:CheckBox ID="All" runat="server" Checked="true" Text="ALL" ForeColor="Black" /><br />
    <asp:CheckBox ID="CheckBox2" runat="server" Text="Accepted" ForeColor="Black" CssClass="chkdisplay" /><br />
    <asp:CheckBox ID="CheckBox3" runat="server" Text="Contacted" ForeColor="Black" CssClass="chkdisplay"  /><br />
    <asp:CheckBox ID="CheckBox4" runat="server" Text="Pending" ForeColor="Black" CssClass="chkdisplay" /><br />
    <asp:CheckBox ID="CheckBox5" runat="server" Text="Pre-Authorized" ForeColor="Black" CssClass="chkdisplay" /><br />
    <asp:CheckBox ID="CheckBox6" runat="server" Text="Show Deleted" ForeColor="Black" CssClass="chkdisplay" /><br />
    <asp:CheckBox ID="CheckBox7" runat="server" Text="Treated" ForeColor="Black" CssClass="chkdisplay" />
</div>

Script i Tried(its not working).I have used asp.net checkbok and cssclass to iterate through I think cssclass does not work like class selector:

$(document).ready(function () {
    $('.chkdisplay').each(function () {
        if ($(this).is(':checked')) {
            $('#All').attr('checked', false);
        }
    });
});

IS there any way i wand to use asp.net checkbox only.When i select any checkbok between 2 to 7 i want checkbok of ID="All" to be unchecked
Thank u

bipen
  • 36,319
  • 9
  • 49
  • 62
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51

4 Answers4

2

i think you can use attribute selector with ^ which gets all the elements beginning with the specified string..

$('[id^="CheckBox"]').each(function () {
bipen
  • 36,319
  • 9
  • 49
  • 62
2

Pay attention: CssClass does not apply to the input element but to a span that wraps the input element. You should iterate each first children of .chkdisplay elements (see also here).

Something like:

$('.chkdisplay > input').each(function () {
    if (this.checked) {
        $('#All').prop('checked', false);
        return false;
    }
});
Community
  • 1
  • 1
mamoo
  • 8,156
  • 2
  • 28
  • 38
0

Give a name to your "All" Checkbox like :

<asp:CheckBox name="ChkTest" ID="All" runat="server" Checked="true" Text="ALL" ForeColor="Black" />

Instead of $('#All').attr('checked', false);

Try this one :

$('#<%= ChkTest.ClientID %>').attr('checked', false);
Pouki
  • 1,654
  • 12
  • 18
0

I have done with the right answer see here http://jsfiddle.net/hZFFr/3/

$('.chkdisplay').on('change blur', function () {;
    $('#All').attr('checked', !($('.chkdisplay').not(':checked').length));

})
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51