title: Why is my form validation not working (onsubmit not triggering)?
body: <p>I am writing a simple registration screen that allows a user to input their email address and password. As standard, I have the user inputting their email address and password twice to confirm. However, the <code>onsubmit</code> attribute on my form does not seem to be executing.</p>
  
  <p>Here is the code:</p>
  
  <p><strong>Fields</strong></p>
  
  <pre><code> &lt;form name="form" id="form" action="" onsubmit="return validateForm()" class="form col-md-12 center-block" method="POST"&gt;
       &lt;div class="form-group"&gt;
            &lt;input type="text" class="form-control input-lg" name="name" id="name" placeholder="Full Name"&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
            &lt;input type="text" class="form-control input-lg" name="email" id="email" placeholder="Email Address"&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
            &lt;input type="text" class="form-control input-lg" name="cemail" id="cemail" placeholder="Confirm Email Address"&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
            &lt;input type="password" class="form-control input-lg" name="password" id="password" placeholder="Password"&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
            &lt;input type="password" class="form-control input-lg" name="cpassword" id="cpassword" placeholder="Confirm Password"&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
            &lt;button class="btn btn-primary btn-lg btn-block" form="form" type="submit" name="register" id="register"&gt;Register&lt;/button&gt;
            &lt;span class="pull-right"&gt;&lt;a href="login.php"&gt;Login&lt;/a&gt;&lt;/span&gt;&lt;br&gt;
       &lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>&lt;script&gt;
      function validateForm() {
        if (isSame(document.getElementById("email"), document.getElementById("cemail"))
         &amp;&amp; isSame(document.getElementById("password"), document.getElementById("cpassword"))) {
          return true;
      } else {
        alert("Confirmation fields do not match, please retype and try again.");
        return false;
      }
  
      function isSame(elementA, elementB) {
        if (elementA.value.trim() == elementB.value.trim()) return true;
        else return false;
      }
  
      //ignore this 
      function submitForm() {
        document.getElementById("form").submit();
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I have tried to debug as much as possible, but it doesn't seem like my submit button is triggering the form's <code>onsubmit</code>. I have viewed the request log, and it is posting the data just fine, however.</p>
  
  <p>Thank you in advance!</p>