Pages

Below is code we can generate Captcha using HTML code:

<html>
<head>
    <script type="text/javascript">
        function Captcha(){
            var alpha = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
            var i;
            for (i=0;i<6;i++){
                var a = alpha[Math.floor(Math.random() * alpha.length)];
                var b = alpha[Math.floor(Math.random() * alpha.length)];
                var c = alpha[Math.floor(Math.random() * alpha.length)];
                var d = alpha[Math.floor(Math.random() * alpha.length)];
                var e = alpha[Math.floor(Math.random() * alpha.length)];
                var f = alpha[Math.floor(Math.random() * alpha.length)];
                var g = alpha[Math.floor(Math.random() * alpha.length)];
            }
            var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
            document.getElementById("mainCaptcha").value = code        }
        function ValidCaptcha(){
            var string1 = removeSpaces(document.getElementById('mainCaptcha').value);
            var string2 = removeSpaces(document.getElementById('txtInput').value);
            if (string1 == string2){
                return true;
            }
            else{
                return false;
            }
        }
        function removeSpaces(string){
            return string.split(' ').join('');
        }

    </script>
</head>
<body onload="Captcha();">
<table>
    <style type="text/css">
        #mainCaptcha { height: 3em; }
    </style>
    <tr>
        <td>
            Generate Captcha<br />
        </td>
    </tr>
    <tr>
        <td>
            <input type="text" size="20" readonly id="mainCaptcha" style="background-image:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXuoMsQWCgr7R072VfsruNW14lgjUB1CcX71U6ZL5zCCtWJE4ZEn0704yh2V1pQQHggaOx-MHeUd70hsG0tvUGoI6qLRlM_sDmkiihPHNpMhUN-Xk_0XHBvRACVSsQPkA6qdub039fHdw/s1600/captcha_lines.png)"/>
            <input type="button" id="refresh" value="Refresh" onclick="Captcha();" />
        </td>
    </tr>
    <br>
    <tr>
        <td>
            <input type="text" id="txtInput" height="100"/>
        </td>
    </tr>
    <tr>
        <td>
            <input id="Button1" type="button" value="Check" onclick="alert(ValidCaptcha());"/>
        </td>
    </tr>
</table>
</body>
</html>
<html>
After executing above code it will generate Captcha like below:

Captcha
Please comment below to feedback or ask questions.


No comments:

Post a Comment

Please comment below to feedback or ask questions.