title: JavaScript form validation function is not working
body: <p>I want to validate this form and I have the javascript written but when I press <kbd>submit</kbd> it doesnt do anything.</p>
  
  <p>Only the <code>pattern=[a-zA-Z]</code> work</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function validation() {
    var name = document.getElementById('name').value;
    var surname = document.getElementById('surname').value;
    var message = document.getElementById('message').value;
    var email = document.getElementById('email').value;
  
    if (name == '' || surname == '' || message == '' || email == '') {
      document.getElementById("eresult").innerHTML = "All fields required"
      return false;
    } else if (name.length &lt; 2) {
      document.getElementById("eresult").innerHTML = "Name must be atleast 2 charachters"
    } else {
      return true;
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;aside id="sidebar"&gt;
    &lt;div class="dark"&gt;
      &lt;form action="#" name="form" method="POST" onsubmit="return validation();"&gt;
        &lt;h3&gt;Get A Quote&lt;/h3&gt;
  
        &lt;div&gt;
          &lt;label&gt;Name&lt;/label&gt;&lt;br&gt;
          &lt;input type="text" name="name" id="name" placeholder="Name" pattern="[a-zA-Z]*"&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;label&gt;Surname&lt;/label&gt;&lt;br&gt;
          &lt;input type="text" name="surname" id="surname" placeholder="Surname" pattern="[a-zA-Z]*"&gt;
        &lt;/div&gt;
  
        &lt;div&gt;
          &lt;label&gt;Email&lt;/label&gt;&lt;br&gt;
          &lt;input type="email" name="email" id="email" placeholder="Email Address"&gt;
        &lt;/div&gt;
  
        &lt;div&gt;
          &lt;label&gt;Message&lt;/label&gt;&lt;br&gt;
          &lt;textarea type="message" name="message" id="email" minlength="1" maxlength="200" placeholder="Message(max 200 characters)"&gt;&lt;/textarea&gt;
        &lt;/div&gt;
  
        &lt;input type="submit" name="submit" value="Submit"&gt;
      &lt;/form&gt;
      &lt;div id="eresult" style="color:red;"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/aside&gt;
  &lt;footer&gt;
    &lt;p&gt;Renars Web Design, Copyright &amp;copy; 2019&lt;/p&gt;
  &lt;/footer&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I expect if I dont enter all fields it should say "All Fields required"
  but it just submits the form.</p>