<head>
<title>Captcha Validation</title>
<script type="text/javascript">
function DrawCaptcha()
{
var a = Math.ceil(Math.random() * 10)+ '';
var b = Math.ceil(Math.random() * 10)+ '';
var c = Math.ceil(Math.random() * 10)+ '';
var d = Math.ceil(Math.random() * 10)+ '';
var e = Math.ceil(Math.random() * 10)+ '';
var f = Math.ceil(Math.random() * 10)+ '';
var g = Math.ceil(Math.random() * 10)+ '';
var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
document.getElementById("txtCaptcha").value = code
}
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2) return true;
return false;
}
function removeSpaces(string)
{
return string.split(' ').join('');
}
</script>
</head>
<body onload="DrawCaptcha();">
<div class="align">
Welcome To Captcha<br />
<input id="txtCaptcha" type="text" readonly="" class="input_img">
<input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" /><br>
<input type="text" id="txtInput"/>
<input id="Button1" type="button" value="Check" onclick="alert(ValidCaptcha());"/>
</div>
<p style="color:#F36">- See more at: http://codingresolved.com/discussion/540/how-to-make-captcha-in-javascript/p1#sthash.3nlKLUxl.dpuf</p>
</body>
</html>
No comments:
Post a Comment