I have a code block that checks certain elements before allowing a form to submit, the loop loops through OK.
I would anticipate, or at least had hoped that the first time it finds a problem, an alert is shown and then execution stops. What is actually happening is that alerts show multiple times, right down to the last one, and only the last one actually returns false!
I don't understand why this is, what am I doing wrong? The JavaScript is below.
$('#deliverInForm').submit(function(){
$('.childRow').each(function(){
if($(this).find('.thisBinName').val()!='' || $(this).find('.unitQty').val()!=''){
if($(this).find('.thisBinName').val()==''){
alert('You have entered a quantity but no Bin, please correct and try again!');
return false;
}else if($(this).find('.unitQty').val()==''){
alert('You have entered a Bin but no quantity, please correct and try again!');
return false;
}else if($(this).find('.unitQty').val()==0){
alert('Can\'t move zero units into a bay, please correct and try again!');
return false;
}else if($(this).find('.unitQty').val()<0){
alert('Can\'t deliver in minus units into a bay, please correct and try again!');
return false;
}
}
});
if($('#supDocNo').val()==''){
alert('Can\'t leave Supplier Reference blank, please correct and try again!');
return false;
}
return true;
});