I am using jQuery validation and I am wanting to display the error message in a div <div class="alert alert-error" id="errorContainer"> The default of showing below the forms does not work with my form design.
The validation script is linked to the page I have the form on and it looks like:
$(function validate() {
var rules = {
rules: {
full_name: {
minlength: 2,
maxlength: 50,
required: true
},
address: {
minlength: 5,
required: true
},
city: {
minlength: 2,
required: true
},
state: {
minlength: 2,
maxlength: 2,
required: true
},
zip: {
minlength:5,
maxlength:5,
required: true
},
phone: {
required: true,
phoneUS: true
},
phone_other: {
required: true,
phoneUS: true
},
email: {
required: true,
email: true
},
date_to_start: {
required: true
},
ssn: {
required: true,
ssn: true,
},
salary: {
required: true
}
}
};
var validationObj = $.extend (rules, Application.validationRules);
$('#employment-application').validate(validationObj);
});
Now I did try changing $('#employment-application').validate(validationObj); to the code below as well as tried adding it to the bottom of the page I have the form on, both gave negative results. The script seems to add style="display:none;" to the errorContainer and does not load any errors anywhere.
(tried changing $('#employment-application').validate(validationObj); to the below)
$("#employment-application").validate({
errorContainer: "#errorContainer",
errorLabelContainer: "#errorContainer",
errorElement: "li"
})
So re-cap, I am wanting to use jQuery Form Validation and display the error messages received in a separate div because the default does not work with my form design.
.validate()method inside of a function namedvalidate(). Then what calls the function? Typically, the.validate()method simply goes inside of a DOM ready event handler.