Simple captcha validation using JQuery

1)Script

$(document).ready(function(){
$(‘#captchaform’).click(function(e){
e.preventDefault();
var firstcap = $(‘#firstcap’).val();
var secondcap = $(‘#secondcap’).val();
var total =$(‘#answercap’).val();
var sum = parseInt(firstcap) + parseInt(secondcap);
if(sum == total)
{
$(“#signinformindex”).submit();
}
else
{
$(“#messagecap”).html(“Captcha didn’t matched !”);
}
});
});

2)Html

<input type=”text” style=”width:20px !important” id=”firstcap” readonly value=”<?php echo rand(1,9);?>” />
+
<input type=”text” style=”width:20px !important” id=”secondcap” readonly value=”<?php echo rand(1,9);?>” /> =
<input type=”text” style=”width:20px !important” id=”answercap” />

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s