Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling multiple Javascript functions onSubmit

Tags:

javascript

I'm trying to call multiple JavaScript functions. It submits even though my functions return false. I receive the alert messages but it submits anyway.

This is my form.

<form name="myform" id="myform" action="receipt.html" method="post" onSubmit="return allValidation();">
like image 884
dafyddgj Avatar asked Jul 25 '26 14:07

dafyddgj


2 Answers

You aren't returning anything in allValidation, so that it will continue to next method execution. Try this,

function allValidation() {
    return validateForm() && selectCountry() && validateEmail();
}
like image 73
Darshan Patel Avatar answered Jul 27 '26 04:07

Darshan Patel


You can use multiple functions and then and their results to get final validation. and also add return true statements in all functions where validation is successful

function allValidation()
   {
      return (validateForm() && selectCountry() && validateEmail());
   }
like image 23
Zohaib Ijaz Avatar answered Jul 27 '26 03:07

Zohaib Ijaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!