title: How to call two functions on a form submit
body: <p>I am trying to do javascript form validation, and to do this I need to call two functions. One for the password and on for the username (I will also need to call more later on). </p>
  
  <p>Here is my JS code:</p>
  
  <pre><code>function validateUserName(NewUser)
  {
      var u = document.forms["NewUser"]["user"].value
      var uLength = u.length;
      var illegalChars = /\W/; // allow letters, numbers, and underscores
      if (u == null || u == "")
      {
          alert("You left Username field empty");
          return false;
      }
      else if (uLength &lt;4 || uLength &gt; 11)
      {
          alert("The Username must be between 4 and 11 characters");
          return fasle;
      }
      else if (illegalChars.test(u)) 
      {
          alert("The username contains illegal characters");
          return false;
      }
      else
      {
          return true;
      }
  }
  
  function validatePassword(pwd, confirmPwd)
  {
      var p = document.forms["NewUser"]["pwd"].value
      var cP = document.forms["NewUser"]["cP"].value
      var pLength = p.length;
      if (p == null || p == "")
      {
          alert("You left the password field empty");
          return false;
      }
      else if (pLength &lt; 6 || pLength &gt; 20)
      {
          alert("Your password must be between 6 and 20 characters in length");
          return false;
      }
      else if (p != cP)
      {
          alert("Th passwords do not match!");
          return false;
      }
  }
  </code></pre>
  
  <p>and here is my HTML form:</p>
  
  <pre><code>&lt;form name = "NewUser" onsubmit= "return validateUserName(), return validatePassword()" action = ""&gt;
                  &lt;tr&gt;
                  &lt;td&gt;Username:&lt;/td&gt; 
                  &lt;td&gt;&lt;input type = "text" name = "user"/&gt;&lt;/td&gt; 
                  &lt;/tr&gt;
                  &lt;tr&gt;
                  &lt;td class = "Information"&gt;&lt;em&gt;Must be 4-11 characters.&lt;br/&gt;Only numbers, letters and underscores.&lt;/em&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                  &lt;td&gt;Password:&lt;/td&gt;
                  &lt;td&gt;&lt;input type = "password" name = "pwd"/&gt;&lt;/td&gt;
                  &lt;tr&gt;
                  &lt;td  class = "Information"&gt;&lt;em&gt;6-20 characters&lt;/em&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                  &lt;td&gt;Confirm Password:&lt;/td&gt;
                  &lt;td&gt;&lt;input type = "password" name = "confirmPwd"/&gt;&lt;/td&gt;
                  &lt;tr&gt;
                  &lt;td  class = "Information"&gt;&lt;em&gt;just in case you didn't make mistakes!&lt;/em&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;input type = "submit" value = "Submit"/&gt;
  </code></pre>
  
  <p>Please ignore the table code.</p>
  
  <p>Should I rather just put it all in one function? Or is there a way to call two functions at once?</p>