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

4 Answers 4

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;
    }
});
1
  • i am using asp.net controls so will $('.chkdisplay > input') input type work? May 28, 2013 at 9:43
2

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

$('[id^="CheckBox"]').each(function () {
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);
0
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));

})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.