How to create capcha code using js ?

in programming •  8 years ago 

How to create Capcha Code using java Script-

Code to create Capcha Code given Below:

<script language="javascript">
    var a = Math.ceil(Math.random() * 9) + '';
    var b = Math.ceil(Math.random() * 9) + '';
    var c = Math.ceil(Math.random() * 9) + '';
    var d = Math.ceil(Math.random() * 9) + '';
    var e = Math.ceil(Math.random() * 9) + '';
    var f = Math.ceil(Math.random() * 9) + '';
    var g = Math.ceil(Math.random() * 9) + '';
    var h = Math.ceil(Math.random() * 9) + '';
    var code = a + b + c + d + e + f + g + h;
    document.getElementById("numcode").value = code;

    function ValidCaptcha() {
        var str1 = removeSpaces(document.getElementById('numcode').value);
        var str2 = removeSpaces(document.getElementById('txtInput').value);
        if (str1 == str2) {
            return true;
            alert(str1);
        } else {
            return false;
        }
    }

    function removeSpaces(string) {
        return string.split(' ').join('');
    }

Enjoy!

Good Luck!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

thats pointless :D The capcha is to prevent automated requests (bots) to the server. your code will just ask the real user but never the "bad guy"