Hello
This must be a very simple problem for JS experts, but I don't know enough yet about JS to know how to solve it.
After successfully adding and using jQuery's form validator, I'd like to add a simple "Please computer a+b" anti-SPAM check.
The problem is how to combine the two?
Here's a simplified example:
Thanks for any help.Code:<head> <script src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.validate.js"></script> <script type="text/javascript"> //========= jQuery form validator jQuery.extend(jQuery.validator.messages, { required: "This field is required.", email: "Please enter a valid e-mail address." }); //========= Simple, anti-spam scheme var a = Math.ceil(Math.random() * 10); var b = Math.ceil(Math.random() * 10); var c = a + b function DrawBotBoot() { document.write("Compute "+ a + " + " + b +"? "); document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>"); } function ValidBotBoot(){ var d = document.getElementById('BotBootInput').value; if (d == c) return true; return false; } //========= ?How to check anti-spam answer + validate other fields in form? $(document).ready(function(){ $("#myform").validate({ /*submitHandler: function(form) { form.submit(); } });*/ }; </script> </head> <body> <form action="send.php" method="post" id="myform"> Name <input type="text" maxlength="25" id="name" name="name" class="required"/> Anti-SPAM check<script type="text/javascript">DrawBotBoot()</script> <input type="submit" class="submit" value="Send" onclick="alert(ValidBotBoot());"/> </form> </body>


Reply With Quote
Bookmarks