2

I have a input type of checkbox in my form, and I want to use jQuery Validation: http://docs.jquery.com/Plugins/Validation

I have it working fine on a dozen other forms of mine, but none of those forms have checkboxes. How can I check to make sure that a checkbox is checked using this plugin?

Currently I have it as such:

...
termsConditions: {
    required: true
}
...

<input type="checkbox" id="termsConditions" name="termsConditions"/> I agree to the <a href="terms">terms and conditions</a>
<label style="float: none;" for="termsConditions" class="error" generated="true"></label>

Nothing happens when I try to validate for it. Any help?

2 Answers 2

4

use "required"

$("#signupForm").validate({
    rules:{
        termsConditions : "required"
    }
});

Or you can simply add the class "required" to your check box.

<input type="checkbox" id="termsConditions" class="required" name="termsConditions"/>

Example on jsfiddle

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

4 Comments

@Sennheiser using "required" or adding the class "required" should work, if not please post more of your html and .validate() options to see if something else is causing issues.
I know why the error is occurring. I have another form right before the checkbox, which may have the validator confused. I switched the order of that form and my checkbox, and it works now.
is it possible to add a custom message to that?
@MarkColeman How about red validation message below the checkbox?
1

Another possible cause might be that the checkbox field was not visible. Validation will be skipped on any hidden inputs.

If you want it to validate hidden fields you can set the ignore option to something other that ignore: 'hidden'.

$('#form').validate({
    ignore: []
});

1 Comment

When you use custom style for inputs, this may the problem. Perfect answer

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.