title: onsubmit method doesn't stop submit
body: <p>My <code>onsubmit</code> is not working. My idea was to put some mandatory fields and, in order to achieve that, I was using the <code>onsubmit</code> method inside a form in HTML that called a JavaScript function.</p>
  
  <p>The idea was if all the mandatory fields were filled, the javascript function would return <code>true</code> and it would move on to page <code>/control/Cadastro.php</code>. Otherwise, if any mandatory field was empty, it would return <code>false</code> and it wouldn't move to page <code>/control/Cadastro.php</code>, staying in the current page until true.</p>
  
  <p>Unfortunately, the function does return <code>false</code> if all the mandatory fields are not filled, as expected, but it still moves to page <code>/control/Cadastro.php</code>, even if it shouldn't.</p>
  
  <p>I'm going to cut off some code to make my point of view perceptible.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script&gt;
              function ValidateRequiredFields()
              {
                  var message = new String('\nCampos obrigatórios:\n');
                  var flag=new Boolean(1);
                  var x=document.forms["theForm"]["nr_processoCA"].value;
                  if (x==null || x==""){
                      message += '\nNº do processo\n'; 
                      flag = new Boolean(0);
                  } 
                  if (flag == false){
                      alert(message);
                  }
                  return flag;    
              }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name="theForm" onsubmit="return ValidateRequiredFields()" method="post" action="../control/Cadastro.php"&gt; 
              Nº do Processo: &lt;br&gt;
              &lt;input type="text" name="nr_processoCA" class="input-xlarge"&gt;
              &lt;br&gt;
              &lt;div class="row-fluid" style="text-align:center;"&gt;
                  &lt;input type="submit" class="btn btn-primary btn-large" value="Gravar"&gt;
              &lt;/div&gt;   
           &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>