title: Two functions in one onclick - Javascript
body: <p>I'm trying to execute two functions at once validating online form. First form works fine but the second is not being executed. Can anyone point out what is wrong with my code? </p>
  
  <pre><code>function both(){
      validation();
      regex();
  }
  
  function validation(){
      var valid = true;
      var error = [];
  
      if (document.check_in.forename.value == ""){
          error.push("First Name");
          valid = false;
      }
      if (document.check_in.surname.value == ""){
          error.push("Surname");
          valid = false;
  }
      if (valid == false) {
          alert("Please fill in the following fields:\n" + error.join("\n") + ".");
      }
      return valid;
  }
  
  function regex(){
      var fnameRE = /^[a-zA-Z]+$/;
  var valid_reg = true; 
      var error_reg = [];
  
      if (!fnameRE.test(document.check_in.forname.value)) {
          error_reg.push("Please use characters only in First Name field.");
          valid_reg = false;
      }   
      else if (valid_reg == false) {
          alert("Please fill s:\n" + error_reg.join("\n") + ".");
      }
      return valid_reg;
  }
  </code></pre>
  
  <p>And HTML: </p>
  
  <pre><code>&lt;form name="check_in" method="POST" action="form.html" onSubmit="return both()"&gt; 
  </code></pre>