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 t
You need to prevent the event's default action before it's bubbled up and handled by the browser. $.getJson returns control and allows the validateZipCode function to finish first, so you need to do this:
function validateZipCode(event){
event.preventDefault(); //stop the form from being submitted
$.getJson(
url,
params,
function(data){
if(data.response === false){
someError.show();
}
}
);
}
$('#someForm').submit(function(event){
validateZipCode(event);
});
$('#zipInput').blur(function(event){
validateZipCode(event);
})