Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to apply validation on checkbox with jQuery?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 289
    Comment on it

    Sometimes we need to check whether a checkbox is checked or not. We can do this easily by using "checked" attribute of a checkbox.

    Example: In the below I have created a function validateCheckBox() that checks whether a checkbox is checked or not.

    <html> 
      <head> 
        <title>Demo to show div</title> 
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript"> 
          function validateCheckBox()
        {
            if($('#addressCheckBox').is(':checked'))
            {
                $('#validaddressCheckBox_error').text("");
            }
            else
            {
                $('#validaddressCheckBox_error').text("You must check the check box in order to proceed.");
            }
        }
        </script>
        <style>
        .error{color: #db4437;font-size:14px;}
        </style>
      </head> 
      <body> 
           <div class="col-xs-8">
              <input type="checkbox" id="addressCheckBox" class="form-control" onClick="validateCheckBox();"> 
              <label>I confirm this is my address</label>
              <span id="validaddressCheckBox_error" class="error emailedCodeError"></span>
           </div>
      </body> 
    </html>
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: