title: return true from javascript then form continue to submit
body: <p>i have php page and javascript, the page is contact us form and before submit button there is captcha  when form submit it checks captcha if it validate return true else alert and create again captcha but it doesn't work when it return true after that nothing happen</p>
  
  <pre><code>&lt;?php
  $action=$_REQUEST['action'];
  if ($action=="")    /* display the contact form */
      {
      ?&gt;
  &lt;form action="" id="demo-form" onsubmit="validateCaptcha()" method="POST" enctype="multipart/form-data" &gt;
      &lt;h3&gt;Quick Contact&lt;/h3&gt;
      &lt;h4&gt;Contact us today, and get reply with in 24 hours!&lt;/h4&gt;
          &lt;input type="hidden" name="action" value="submit"&gt;
        &lt;input placeholder="Your name" name="name" id="name" type="text" tabindex="1" required autofocus&gt;&lt;br&gt;
  
        &lt;input placeholder="Your Email Address" name="email" id="mail" type="email" tabindex="2" required&gt;&lt;br&gt;
  
        &lt;input placeholder="Subject" id="sub" name="subject" type="text" tabindex="3" required&gt;&lt;br&gt;
  
        &lt;input placeholder="Mobile Number" name="number" pattern="^((\+92)|(0092)|(0))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$" id="contactInformation" type="tel" tabindex="4" oninvalid="this.setCustomValidity('Enter mobile number like: 03001234567')"
        oninput="this.setCustomValidity('')" &gt; &lt;br&gt;
        &lt;textarea placeholder="Type your Message Here...." tabindex="6" name="message" id="msg" tabindex="5" required&gt;&lt;/textarea&gt;&lt;br&gt;
        &lt;div id="captcha"&gt;
      &lt;/div&gt;&lt;input type="text" placeholder="Enter Captcha Code Here" id="cpatchaTextBox"/&gt;&lt;br&gt;
        &lt;input name="submit" type="submit" value="Submit" tabindex="7" id="contact-submit" data-submit="...Sending" /&gt;&lt;br&gt;
          &lt;button type="reset" name="reset" tabindex="8" id="contact-reset"&gt;Clear Form&lt;/button&gt;
   &lt;/form&gt;
  &lt;?php
      } 
  else                /* send the submitted data */
      {
      $name=$_REQUEST['name'];
      $email=$_REQUEST['email'];
      $subject=$_REQUEST['subject'];
      $number=$_REQUEST['number'];
      $message=$_REQUEST['message'];
      if (($name=="")||($email=="")||($subject=="")||($number=="")||($message==""))
          {
          echo "All fields are required, please fill &lt;a href=\"\"&gt;the form&lt;/a&gt; again.";
          }
      else{        
          $from="From: $name&lt;$email&gt;\r\nReturn-path: $email";
          $msg= "Name: ".$name."\nContact Number: ".$number."\n".$message ;
          mail("xyz@gmail.com", $subject, $msg , $from);
          echo '&lt;script type="text/javascript"&gt;',
          'alert("EMAIL SENT..!");',
          'setTimeout(function(){',
            ' window.location.href = "thanks.php";',
          ' }, 50);',
          '&lt;/script&gt;'
  ;
          }
      }  
  ?&gt;
  
  &lt;/div&gt;
              &lt;/section&gt;
  
                 &lt;/div&gt;
      &lt;br/&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt; 
  
  
  </code></pre>
  
  <pre><code>// JavaScript Document
  var code;
  function createCaptcha() {
    //clear the contents of captcha div first 
    document.getElementById('captcha').innerHTML = "";
    var charsArray =
    "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@!#$%^&amp;*";
    var lengthOtp = 6;
    var captcha = [];
    for (var i = 0; i &lt; lengthOtp; i++) {
      //below code will not allow Repetition of Characters
      var index = Math.floor(Math.random() * charsArray.length + 1); //get the next character from the array
      if (captcha.indexOf(charsArray[index]) == -1)
        captcha.push(charsArray[index]);
      else i--;
    }
    var canv = document.createElement("canvas");
    canv.id = "captcha";
    canv.width = 100;
    canv.height = 50;
    var ctx = canv.getContext("2d");
    ctx.font = "25px Georgia";
    ctx.strokeText(captcha.join(""), 0, 30);
    //storing captcha so that can validate you can save it somewhere else according to your specific requirements
    code = captcha.join("");
    document.getElementById("captcha").appendChild(canv); // adds the canvas to the body element
  }
  function validateCaptcha() {
    event.preventDefault();
  
    if (document.getElementById("cpatchaTextBox").value == code) {
      return true;
    }else{
      alert("Invalid Captcha. try Again");
      createCaptcha();
    }
  }
  
  </code></pre>
  
  <p>kindly if anyone can do that for me i just want, when captcha validate the form submit and email sent to the person.</p>