Skip to content

Instantly share code, notes, and snippets.

@willwright82
Created July 10, 2014 16:07
Show Gist options
  • Save willwright82/4c7f08571b1b6708f051 to your computer and use it in GitHub Desktop.
Save willwright82/4c7f08571b1b6708f051 to your computer and use it in GitHub Desktop.
Are you human? Math captcha
<!DOCTYPE html>
<html lang="en">
<head>
<title>Are You Human?</title>
<script type="text/javascript">
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 10);
var c = a + b
function DrawBotBoot() {
document.write("What is " + a + " + " + b + "? ");
document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>");
}
function ValidBotBoot() {
var d = document.getElementById('BotBootInput').value;
if (d == c) {
$('#submit').removeAttr("disabled");
$(".answer").detach();
$('#captchaform').append('<p class="answer">Correct!</p>');
return true;
} else {
$(".answer").detach();
$('#captchaform').append('<p class="answer">Wrong! Are you human?</p>');
return false;
}
}
</script>
</head>
<body>
<div id="captchaform" class="form-group col-lg-12">
Are you human?
<br />
<script type="text/javascript">
DrawBotBoot()
</script>
<input id="captcha" type="hidden" name="contact_captcha" value="ValidBotBoot();">
<input id="Button1" type="button" value="Check answer" onclick="ValidBotBoot();" />
</div>
<div class="form-group col-lg-12">
<input type="hidden" name="save" value="contact">
<button id="submit" type="submit" class="btn btn-primary" disabled="disabled">Submit</button>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment