Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple form onsubmit validations?
    text
    copied!<p>I have a form and currently I have a javascript code to validate my form to make sure that the user fills out every input. my form action includes:</p> <pre><code>onsubmit="return validateForm();" </code></pre> <p>Which is the javascript to make sure every field is filled out. If it makes any difference, here is my javascript code:</p> <pre><code>&lt;script type="text/javascript"&gt;// &lt;![CDATA[function validateForm() { var a=document.forms["myform"]["inf_field_FirstName"].value; var b=document.forms["myform"]["inf_field_Email"].value; var c=document.forms["myform"]["inf_field_Phone1"].value; if (a==null || a=="" || a=="First Name Here") { alert("Please enter your First Name!"); return false; } if (c==null || c==''|| c=="Enter Your Phone Here") { alert("Please insert your phone number!"); return false; } var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; if (document.myform.inf_field_Email.value.search(emailRegEx) == -1) { alert("Please enter a valid email address."); return false; } } // ]]&gt; &lt;/script&gt; </code></pre> <p>However on the phone number field, defined at c, I want to add another script that will pop up if the user doesn't enter a phone number at least 9 digits long. I was thinking of adding a code like this</p> <pre><code>&lt;script type="text/javascript"&gt; function validate(){ var c=document.forms["myform"] if (input.length&lt;9){ alert("Please enter a real phone number") return false }else { return true } } &lt;/script&gt; </code></pre> <p>However I don't know how to run both functions on submit. I am extremely new to javascript so excuse me if there's already a simple solution to this.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload