Reputation: 8882
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?
Upvotes: 2
Views: 8258
Reputation: 2443
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: []
});
Upvotes: 1
Reputation: 40863
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"/>
Upvotes: 4