The main reason for your problem is that you return false from the validation methods, even if everything is ok.
First, the easy part combines two methods:
I would not do inline js, but stick to what you have ... just create a method that combines both functions:
<script> function doBoth() { return validateForm() && checkEmail(); } <script> ... <form name="myForm" onsubmit="return doBoth()" method="post">
Secondly, fixing a short circuit problem
However, there is an error with your two methods, you implicitly return undefined from them. undefined is false, so doBoth will never get the second method. This is due to a short circuit . JS is lazy, therefore, if the first part of the && operator is false, JS stops and does not evaluate the second part, since now there is no way for the whole operator to be true.
The solution to this problem is to return true if everything is verified correctly.
Also, note that you are missing the closing parenthesis in validateForm
<script> function validateForm() { var x=document.forms["myForm"]["name"].value; if (x==null || x=="") { alert("Name text box must be filled out"); return false; } // everything ok *this is a MUST to return* return true; } function checkEmail() { var y=document.forms["myForm"]["email"].value; var atpos=y.indexOf("@"); var dotpos=y.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=y.length) { alert("Not a valid e-mail address"); return false; } // everything ok *this is a MUST to return* return true; } </script>
source share