Because the .each() method calls a callback function you can't return from the submit from inside the .each() callback. So, you have to set a variable for your return value and then return that later.
$('form').submit(function(){
var retVal = true;
$(this).find('input').each(function(){
if($(this).hasClass('error'))
retVal = false;
return false;
});
return(retVal);
});
You could also solve this problem by letting the selector engine do your searching rather than iterating yourself with .each() like this:
$('form').submit(function(){
if ($(this).find('input.error').length != 0) {
return(false);
}
});
or a little more succinctly:
$('form').submit(function(){
return($(this).find('input.error').length == 0);
});