CREATE SIMPLE CAPTCHA USING JAVASCRIPT AND HTML

<!DOCTYPE html>
<html>

  <head>
    <script type="text/javascript">
    
    var test="";
    
     function textGenerator(){
       test="";
       var text="";
       for(var i=0;i<4;i++){
         text=text+Math.floor(Math.random()*10);
       }
       test=text.toString();
       document.getElementById("captcha").innerHTML = text.toString();
     }
     
     function crosscheck(){
       if(test===document.getElementById("captchaText").value){
         alert("right = "+test);
       }
       else{
         alert("wrong = "+test);
       }
     }
     
    </script>
  </head>

  <body onload="textGenerator()">
    <h1>Captcha example</h1>
    <div id="captcha" style="border:1px solid black;width:120px;font-size:60px;background-color:grey;text-decoration: line-through;">
    </div>
    <input type="text" placeholder="enter captcha" id="captchaText"><br/>
    <input type="button" value="submit" onclick="crosscheck()"/>
    <input type="button" value="reset" onclick="textGenerator()"/>
  </body>

</html>

Comments

Popular Posts