I'm doing some form validation, and I'm having trouble with what I'm trying to accomplish. I want to be able to validate my zip code on blur of the field, but also call the same function to validate zip on submit of the form, and prevent the form from being submitted if the zip code is invalid. My code (generically) goes something like this.
function validateZipCode(event){
$.getJson(
url,
params,
function(data){
if(data.response === false){
someError.show();
event.preventDefault(); //stop the form from being submitted
}
}
);
}
$('#someForm').submit(function(event){
validateZipCode(event);
});
$('#zipInput').blur(function(event){
validateZipCode(event);
})
I've tried using the methods located in this jQuery pass more parameters into callback post, but I still can't seem to accomplish what I need. Any help is appreciated.