javascrpt captcha
<html>
<head>
<title>Captcha</title>
<script type="text/javascript">
//Created / Generates the captcha function
function DrawCaptcha()
{
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length =6;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.getElementById("txtCaptcha").value = randomstring
}
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2)
return true;
else
{
alert("Invalid captcha value");
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string)
{
return string.split(' ').join('');
}
</script>
</head>
<body onLoad="DrawCaptcha();">
<table>
<tr>
<td>
Welcome To Captcha<br />
</td>
</tr>
<tr>
<td>
<input type="text" id="txtCaptcha" disabled="true"
style="background-image:url(captcha_bg.jpg); text-align:center; border:none;
font-weight:bold; font-family:Arial, Helvetica, sans-serif; font-size:16px;line-height:12px;" />
<input type="button" id="btnrefresh" value="Refresh" onClick="DrawCaptcha();return false;" />
</td>
</tr>
<tr>
<td>
<input type="text" id="txtInput"/>
</td>
</tr>
<tr>
<td>
<input id="Button1" type="button" value="Check" onClick="alert(ValidCaptcha());"/>
</td>
</tr>
</table>
</body>
</html>
<head>
<title>Captcha</title>
<script type="text/javascript">
//Created / Generates the captcha function
function DrawCaptcha()
{
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length =6;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.getElementById("txtCaptcha").value = randomstring
}
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2)
return true;
else
{
alert("Invalid captcha value");
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string)
{
return string.split(' ').join('');
}
</script>
</head>
<body onLoad="DrawCaptcha();">
<table>
<tr>
<td>
Welcome To Captcha<br />
</td>
</tr>
<tr>
<td>
<input type="text" id="txtCaptcha" disabled="true"
style="background-image:url(captcha_bg.jpg); text-align:center; border:none;
font-weight:bold; font-family:Arial, Helvetica, sans-serif; font-size:16px;line-height:12px;" />
<input type="button" id="btnrefresh" value="Refresh" onClick="DrawCaptcha();return false;" />
</td>
</tr>
<tr>
<td>
<input type="text" id="txtInput"/>
</td>
</tr>
<tr>
<td>
<input id="Button1" type="button" value="Check" onClick="alert(ValidCaptcha());"/>
</td>
</tr>
</table>
</body>
</html>
Comments
Post a Comment