0
$(document).ready(function() {
$('#chkRFI').click(
         function() {
             $("INPUT[type='checkbox']").attr('checked', $('#chkRFI').is(':checked'));
         });   }); 


<div class="grid_3">
                <div class="box">
                    <div class="boxheader">
                        <asp:CheckBox ID="chkRFI" runat="server" Text="RFI" />
                    </div>
                    <div class="boxbody">
                        <asp:CheckBoxList ID="chklstRFI" runat="server" CssClass="boxbodylist">
                            <asp:ListItem Text="RFI No" Value="RFI" />
                            <asp:ListItem Text="RFI Date" Value="RFI_Date" />
                        </asp:CheckBoxList>
                    </div>
                </div>
            </div>

How to solve? Please provide me any ideas... Thanks

1
  • for badge, u can go and check that link.... Badges Commented Jul 6, 2011 at 7:19

4 Answers 4

2

You should use $('#<%= chkRFI.ClientID %>') instead of $('#chkRFI')

Sign up to request clarification or add additional context in comments.

4 Comments

$(document).ready(function() { $('#<%= chkRFI.ClientID %>').click( function() { $("INPUT[type='checkbox']").attr('checked', $('#<%= chkRFI.ClientID %>').is(':checked')); }); }); so i changed like that, still cannot :( but If I used like that, '#ctl00_Body_chkRFI' is okay... but u know it's so funny..
I think you changed from chkRFI to checkAll. Please change it to $('#<%= chkAll.ClientID %>') . Can you also update the whole code?
no bro... I didn't change. that's my asp code <asp:CheckBox ID="chkRFI" runat="server" Text="RFI" /> //Check All <asp:CheckBoxList ID="chklstRFI" runat="server" CssClass="boxbodylist"> // Check list <asp:ListItem Text="RFI No" Value="RFI" /> <asp:ListItem Text="RFI Date" Value="RFI_Date" /> </asp:CheckBoxList>
oh! my one's using windows authentication for intranet :( sorry for that bro
1

I feel that solution by ysrb should work - but you may also try alternate selectors - for example:

var checkAll = $('.boxheader input');
checkAll.click(function() { 
   $('.boxbody input').attr('checked', checkAll.attr('checked'));
});

1 Comment

yes bro... your one is really worked... and @ysrb 's one also should work cos wherever I search for solution... all solutions are like him... but I don't know why
1

If you are using ASP.NET then all element IDs will be generated in very ugly form, e.g. $Form1$$MyCheckBox (in is not exactly the correct sample, but it shows the main idea). If you are using ASP.NET 4 you can disable this feature in web.config ([pages clientIDMode="static" /]). Analyze your checkbox with FireBug or simply view the page source to make sure that checkbox was generated with correct ID. Hope this helps...

1 Comment

oh! my one is 3.5 SP1, but ur information is really nice... thanks
0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Check/Uncheck All CheckBoxes Using JQuery</title>

    <script src="Scripts/jquery-1.2.6.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $('#chkAll').click(
             function() {
                 $("INPUT[type='checkbox']").attr('checked', $('#chkAll').is(':checked'));
             });
         });    

     </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:CheckBox ID="chkAll" runat="server" Text="Check All" /><br />

        <asp:CheckBoxList ID="cbList" runat="server">
        </asp:CheckBoxList>

    </div>
    </form>
</body>
</html>

here is the complete example

1 Comment

same with my one, right? but not working... I think cos of seperate div, is it true?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.