Skip to content Skip to sidebar Skip to footer

Javascript Form Validator Conflict With Math Captcha

Here is a basic email form with math Captcha. Captcha is working, but the form validator is not. When I say form validator, I am referring to the required 'Name' and 'Email' fields

Solution 1:

Your onsubmit part can't be done this way. If the security code is correct you are returning undefined which is not false and therefor the form gets submitted before the MM_validateForm function gets called which checks the required fields.

Remove the onsubmit=... part from your markup and add the following code to your site

<scripttype="text\javascript">window.onload = function() {
        var form = document.getElementsByTagName("form")[0];    // get the form
        form.onsubmit = function() {
            if (checkform(this) != false) {
                MM_validateForm('name', '', 'R', 'email', '', 'RisEmail');
                returndocument.MM_returnValue;
            } else {
                returnfalse;
            }
        };
    }
</script>

Demo

Post a Comment for "Javascript Form Validator Conflict With Math Captcha"