Create a JavaScript Captcha Example for Learning...

Last updated:9/18/2020 5:46:32 AM

1 Answers

Sanat Shukla
Sanat Shukla

JavaScript Captcha Example

<head><title>JavaScript Captcha Example</title></head>
<body onload="generateCaptcha()">
var captcha;
function generateCaptcha() {
    var a = Math.floor((Math.random() * 10));
    var b = Math.floor((Math.random() * 10));
    var c = Math.floor((Math.random() * 10));
    var d = Math.floor((Math.random() * 10));

    document.getElementById("captcha").value = captcha;
function check(){
 var input=document.getElementById("inputText").value;
  alert("Not Equal");
<input type="text" id="captcha" disabled/><br/><br/>
<input type="text" id="inputText"/><br/><br/>
<button onclick="generateCaptcha()">Refresh</button>
<button onclick="check()">Submit</button>

Note: Please don’t use this method in live web projects because this implementation is already readable by the attacker and he/she can manipulate it. Everything should be processed on the server side. You can just use this captcha generation method in your school or college projects.