title: Simple JavaScript captcha using random array
body: <p>I have created a simple Javascript Captcha but currently the values are randomly generated but I want to get values from the array only(want to randomized these two array), plz check my code I want to do this using simple Javascript with no dependency also plz fix the function validate().</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  
  &lt;script type="text/javascript"&gt;
  
  function myCaptcha() {
  var leftnum =[5, 10, 15, 20];
  var rightnum =[2, 4, 6, 8];
  
  var leftnum = Math.floor(Math.random()*11);
  var rightnum = Math.floor(Math.random()*11);
  
  
  var tolnum = leftnum + rightnum ;
  
  document.getElementById("sh").innerHTML = leftnum + " + " + rightnum;
  
  }
  
  function validate() {
      var captchanow = document.getElementById("captcha");
  
      if (captchanow != "") {
      alert("Please enter a captcha");    
          return false;
      }
      else if(captchanow == tolnum) {
          alert("wrong captcha entered"); 
          return false;
      }
      else {
          form.submit
      }
      return true;
  
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body onload="myCaptcha()"&gt;
  
  &lt;form action="" method="post" onsubmit="return false;"&gt;
    &lt;p&gt;Captcha :
    &lt;input name="captcha" type="text" id="captcha" value="" /&gt;
  
    &lt;label id="sh" value=""&gt;&lt;/label&gt;&lt;/p&gt;
    &lt;p&gt;
      &lt;input type="submit" name="button" id="button" value="Submit" onclick="validate()"/&gt;
    &lt;/p&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>