0

This is how I use jquery validation plugin wit input text:

$('input[id$=txtFirstname]').rules('add', { required: true });

and it works, but if want to use it for checkboxes and select it doesn't work...

$('input[id$=txtFirstname]').rules('add', { required: true, minlength: 2 });
1
  • What selector are you using to access the checkboxes/selects? Commented Sep 8, 2011 at 11:43

1 Answer 1

1

Try using:

<form id='signupForm'>
    <input type='checkbox' name='topic' value='1'>Topic1
    <input type='checkbox' name='topic' value='2'>Topic2
    <input type='checkbox' name='topic' value='3'>Topic3
    </form>

$().ready(function() {
$("#signupForm").validate({
        rules: {
            topic: {
                required: "#newsletter:checked",
                minlength: 2
            },
},
messages: {
            topic: "you must select atleast 2 checkboxes"
}
});
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, that works for check boxes, but doesn't for select: $('input[id$=ddlCountries]').rules('add', { required: 'input[id$ = ddlCountries]:selected' });
For select you could use class='required' ??

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.