Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 4 check boxes in my page. Also I have a select all check box.
When i check on Select all, I need to select all these checkbox given below.
Please help me to solve this using javascript.

ASP.NET
<div class="table_column_50L">
                            <asp:CheckBox ID="chkCertMain" runat="server" Text="Certificate main document" CssClass="checkbox-style-vertical"
                                AutoPostBack="false" />
                        </div>
                        <div class="table_column_50R">
                            <asp:CheckBox ID="chkCertRelated" runat="server" Text="Certificate related document"
                                CssClass="checkbox-style-vertical" AutoPostBack="false" />
                        </div>
                        <div class="table_column_50L">
                            <asp:CheckBox ID="chkSurveyMain" runat="server" Text="Survey main document" CssClass="checkbox-style-vertical"
                                AutoPostBack="false" />
                        </div>
                        <div class="table_column_50R">
                            <asp:CheckBox ID="chkSurveyRelated" runat="server" Text="Survey related document"
                                CssClass="checkbox-style-vertical" AutoPostBack="false" />
                        </div>
Posted

 
Share this answer
 
Hi please call javascript function from onclientclick event of Button in your code

ANd the function is

XML
<script>
function checkAllCheckBox()
{
    $('.checkbox-style-vertical').attr('checked','checked');
}

</script>
 
Share this answer
 
JavaScript
<script type="text/javascript">
        $(document).ready(function () {
            $(".chkSelectAll").click(function () {
                var aa = $(this).attr("checked");
                if (aa) {
                    $(".checkbox-style-vertical").attr("checked", "checked");
                }
                else
                    $(".checkbox-style-vertical").removeAttr("checked");

            });
        });
    </script>


in the above jquery code i suppose that your select all check box has css class applied and its name is .chkSelectAll (please replace that class name with your original css class name)

i have used class name selector of jquery to select your all check boxes using ".checkbox-style-vertical" this class name, and also use attr method to set attribute to checked all the check boxes and removeattr to remove all the check boxes
 
Share this answer
 
hi try this code..


XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery.js.js"></script>
    <script type="text/javascript">

        var SelectCheckbox = function (thisctrl) {

            var flag = thisctrl.checked;
            document.getElementById('<%= chkCertMain.ClientID %>').checked = flag;
            document.getElementById('<%= chkSurveyRelated.ClientID %>').checked = flag;
            document.getElementById('<%= chkSurveyMain.ClientID %>').checked = flag;
            document.getElementById('<%= chkCertRelated.ClientID %>').checked = flag;


        }




    </script>

</head>
<body>
    <form id="form1" runat="server">
        <asp:CheckBox ID="chkSelectAll" runat="server" Text="Select All" onclick="SelectCheckbox(this);" />

        <div class="table_column_50L">
            <asp:CheckBox ID="chkCertMain" runat="server" Text="Certificate main document" CssClass="checkbox-style-vertical"
                AutoPostBack="false" />
        </div>
        <div class="table_column_50R">
            <asp:CheckBox ID="chkCertRelated" runat="server" Text="Certificate related document"
                CssClass="checkbox-style-vertical" AutoPostBack="false" />
        </div>
        <div class="table_column_50L">
            <asp:CheckBox ID="chkSurveyMain" runat="server" Text="Survey main document" CssClass="checkbox-style-vertical"
                AutoPostBack="false" />
        </div>
        <div class="table_column_50R">
            <asp:CheckBox ID="chkSurveyRelated" runat="server" Text="Survey related document"
                CssClass="checkbox-style-vertical" AutoPostBack="false" />
        </div>


    </form>

</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900