I am facing what seems like a straightforward JavaScript issue, but my knowledge in this area is still limited.
Following a successful implementation of basic anti-SPAM feature that asks the user to solve a simple math problem, how can I integrate jQuery's form validator into the form submission process?
<html>
<head>
<script type="text/javascript">
var x = Math.ceil(Math.random() * 10);
var y = Math.ceil(Math.random() * 10);
var z = x + y
function DisplayCaptcha()
{
document.write("Result of "+ x + " + " + y +"? ");
document.write("<input id='CaptchaInput' type='text' maxlength='2' size='2'/>");
}
function ValidateCaptcha(){
var answer = document.getElementById('CaptchaInput').value;
if (answer == z) return true;
return false;
}
</script>
<script>
//Utilized by jQuery for validating form fields
$(document).ready(function(){
$("#myform").validate();
</script>
</head>
<body>
<form action="send.php" method="post" id="myform">
<input type="text" maxlength="25" id="name" name="name" class="required"/>
Are you human?<br />
<script type="text/javascript">DisplayCaptcha()</script>
<input id="SubmitButton" type="button" value="Send" onclick="alert(ValidateCaptcha());"/>
</form>
</body>
</html>
Many thanks!