0

I'm getting a syntax error using jquery validate plugin. I want to target classes and not field names which is why I am using the following syntax:

$("#myFormID").validate({        
    $('.optionSelectClass').rules("add", {
        required: true
    });       

    $('.optionSelectClass').messages("add", { 
        required: "Please select an option"    
    });

}); 

Firebug console says missing : after property id

Any idea's?

1 Answer 1

1

When defining an object using object literal syntax, don't put an ; after each key: value pair declaration:

{
    required: true
}

Object literals are declared via comma separated key: value pair declarations:

{
    required: true, // note the comma
    minLength: 4,   // note the comma
    maxLength: 10   // note _no_ comma; this will throw a SyntaxError in IE
}
Sign up to request clarification or add additional context in comments.

1 Comment

O yes of course, thanks. I took out the semi colons, but I still have the same syntax error in console.

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.