title: Form submission after Javascript Validation
body: <p>I want to submit my form to a <code>PHP</code> file called <code>reg.php</code> after validating it using <code>JavaScript</code>. The <code>HTML</code> form is given below:</p>
  
  <p><strong>HTML Form:</strong></p>
  
  <pre><code>&lt;form method="post"&gt;
     &lt;input type="text" id="username" name="username"&gt;&lt;/input&gt;        
     &lt;button type="button" onclick="val()"&gt;Sign Up&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>JavaScript Validation</strong></p>
  
  <p>The following is the <code>JavaScript</code> validation code:</p>
  
  <pre><code>function val(){
  
      var uname = document.getElementById('username').value;
      if(!uname){
          document.getElementById("error").innerHTML = "Enter a username";
          return false;
      }
      else{
          // I want to submit form if this else statement executes.
      }
  
  
  }
  </code></pre>