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
    • 319
    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.

    1. <html>
    2. <head>
    3. <title>Demo to show div</title>
    4. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    5. <script type="text/javascript">
    6. function validateCheckBox()
    7. {
    8. if($('#addressCheckBox').is(':checked'))
    9. {
    10. $('#validaddressCheckBox_error').text("");
    11. }
    12. else
    13. {
    14. $('#validaddressCheckBox_error').text("You must check the check box in order to proceed.");
    15. }
    16. }
    17. </script>
    18. <style>
    19. .error{color: #db4437;font-size:14px;}
    20. </style>
    21. </head>
    22. <body>
    23. <div class="col-xs-8">
    24. <input type="checkbox" id="addressCheckBox" class="form-control" onClick="validateCheckBox();">
    25. <label>I confirm this is my address</label>
    26. <span id="validaddressCheckBox_error" class="error emailedCodeError"></span>
    27. </div>
    28. </body>
    29. </html>

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: