I’m using the validation plugin of jQuery to check some values of my form. The validation works fine, but now I’d like to check something else, before submitting the form.
This is the additional check, which should only be run after all fields of the form have been validated successfully:
$("#formname").submit(function() {
if($("#input").val() == $("#hiddenInput").val() {
// Everything fine, may submit
return true;
} else {
// Check wasn't successfull, let's alert
alert("Fix the input");
return false;
}
})
This is the actual validation with the plugin:
$("#formname").validate({
rules: {
ou: {
required: true,
minlength: 2,
number: true
},
directors: {
required: true,
number: true
}
},
messages: {
ou: {
required: "Message",
minlength: "Message",
number: "Message"
},
directors: {
required: "Message",
number: "Message"
}
},
errorPlacement: function ($error, $element) {
var name = $element.attr("name");
$("#" + name + "Error").append($error);
}
})
I did actually add the first code snippet to the beginning, but it will be run every time I click on submit, no matter if the validation itself was successfull. Is there some kind of validation return code or event I could check for?
assuming same plugin, add
to your validate, reference here
alternatively add a rule such as this:
Which will validate it just like the rest of your validation.