Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 4 check boxes on the web page, i want client side validation that ate least one check box should be check before submitting the form.

So, Far i have write the following code to validate a single check box.

C#
   <asp:CheckBox ID="CheckBoxTermsandCondition" runat="server" Font-Names="Calibri" Font-Size="Small" ForeColor="Black" />  I Agree with Terms and Condition
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="You Must Agree Upon our terms and condition" ClientValidationFunction = "ValidateCheckBox"></asp:CustomValidator><br /></div>


JavaScript
<script type = "text/javascript">
      function ValidateCheckBox(sender, args) {
          if (document.getElementById("<%=CheckBoxTermsandCondition.ClientID %>").checked == true) {
              args.IsValid = true;
          } else {
              args.IsValid = false;
          }
      }
  </script>
Posted

Try this jquery :

JavaScript
var checked = 0;

$("input[type=checkbox]").live("click", function() {
    if($(this).attr("checked")) checked++;
    else checked--;
}
//Then you would be able to test like this.

if(checked === 0) {
    doSomething();
}
 
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