title: Javascript not loading onClick validate form before loading php page
body: <p>I'm writing a piece of HTML and JavaScript code and I need to check if inputs have been filled before clicking the button. However, when I leave them blank, it proceeds to the php page passing the variables empty.
  I have made some tests and I've concluded it does not load the onClick function at all.
  This is the code (without all the CSS stuff):</p>
  
  <pre><code>      &lt;div class = "register"&gt;
      &lt;form action = "register.php" method = "post" name = "reg1" id = "register" onClick = "return validateForm();"&gt;
        &lt;input type = "text" class = "reg" id = "name" name = "name"/&gt;
         &lt;div class = "alert" id = "inserthere1"&gt; &lt;/div&gt;
        &lt;input type = "text" class = "reg" id = "surname" name = "surname"/&gt; &lt;div class = "alert" id = "inserthere2"&gt;&lt;/div&gt;
        &lt;input type = "text" class = "reg" id = "mail" name = "mail" /&gt;&lt;div class = "alert" id = "inserthere3"&gt;&lt;/div&gt;
        &lt;input type = "submit" value = "Join!" &gt;
        &lt;/form&gt;
      &lt;/div&gt;
  
    &lt;script language = "JavaScript"&gt;
      function validateForm() {
        var n = document.getElementById("name").value;
        var c = document.getElementById("surname").value;
        var m = document.getElementById("mail").value;
        alert("Nome:"+n+"Cognome:"+c+"Mail:"+m);
        document.getElementById("inserthere1").innerHTML = (n===null || n==="" ? '&lt;i&gt; This cannot be left empty. &lt;/i&gt;' : '');
        document.getElementById("inserthere2").innerHTML = (c===null || c==="" ? '&lt;i&gt; This cannot be left empty. &lt;/i&gt;' : '');
        document.getElementById("inserthere3").innerHTML = (m===null || m==="" ? '&lt;i&gt; This cannot be left empty. &lt;/i&gt;' : '');
        if ( n===null || c===null || n==="" || c==="" || m===null || m==="" )
          return false;
          }
        return true;
        }
  </code></pre>
  
  <p></p>