A newbie to jQuery. I am attempting use an array to auto populate elements for form validation. For some reason data.result[1].form_field leads to an "Uncaught SyntaxError: Unexpected token ." error.
var $Form = $("#form").validate({
// Rules for form validation
rules : {
data.result[1].form_field : {
required : true,
range: [data.result[1].minimum, data.result[1].maximum]
}
},
// Do not change code below
errorPlacement : function(error, element) {
error.insertAfter(element.parent());
}
});
Strangly, if I directly write in the field name things work fine.
var $Form = $("#form").validate({
// Rules for form validation
rules : {
some_field : {
required : true,
range: [data.result[1].minimum, data.result[1].maximum]
}
},
// Do not change code below
errorPlacement : function(error, element) {
error.insertAfter(element.parent());
}
});
Not sure why data.result[1].minimum, data.result[1].maximum work, but data.result[1].form_field does not.