validate_form() isn't returning a value, so it won't stop the submit.
your return clauses are within the closure for the each method, so
they're not being passed down.
You'll need to do something like this:
function validate_form() {
var pass = true;
$("select[id^='products']").each(function(){
if(this.value == "0") {
alert('MESSAGE1');
document.getElementById(this.id).focus();
pass = false;
} else if(this.value==14 && document.getElementById('address').value == "") {
alert('MESSAGE2');
document.getElementById('address').focus();
pass = false;
}
return pass;
});
return pass;
}
Cheers,
David
Mahmoud M. Abdel-Fattah wrote:
> yes, it does.
>
> On Feb 26, 2:36 am, James <
james.gp....@gmail.com> wrote:
>
>> So what happens if your validate_page() is only:
>>
>> function validate_form() {
>> return false;
>>
>> }
>>
>> Does it submit?
>>
>> On Feb 25, 2:31 pm, "Mahmoud M. Abdel-Fattah" <
engm...@gmail.com>
>> wrote:
>>
>>
>>> no, there isn't any error!
>>> I did removed return false; from onSubmit handler , but nothing new !!
>>> the form proceed to submit without STOP ! the alert appears & when I
>>> click ok, it goes to the next page with no stop !
>>>
>>> Thanks for your time,
>>> Mahmoud Abdel-Fattah
>>>
>>> On Feb 26, 2:12 am, James <
james.gp....@gmail.com> wrote:
>>>
>>>> Are there any errors that returned? Usually it's a JS error the
>>>> cripples the code and makes it submit regardless.
>>>> What happens if validate_form() only contains "return false"? Does it
>>>> not submit?
>>>>
>>>> You should probably remove the "return false" on the onsubmit handler
>>>> or else it'll never submit since you don't have anything in your JS to
>>>> tell it to submit (eg. form.submit()).
>>>>
>>>> On Feb 25, 1:40 pm, "Mahmoud M. Abdel-Fattah" <
engm...@gmail.com>
>>>>