验证码验证问题

时间:2011-10-19 03:17:07

标签: javascript javascript-events

我创建了一个Captcha验证器,但它覆盖了验证整个表单并提交它的Dreamweaver Spry验证器。如何让它附加到spry验证器或与spry验证器一起使用。验证码验证器如下。我不希望它提交表格。我希望它继续使用验证整个表单的spry验证器。

function checkform(theform){
        var why = "";

        if(theform.txtInput.value == ""){
            why += "- Security code should not be empty.\n";
        }
        if(theform.txtInput.value != ""){
            if(ValidCaptcha(theform.txtInput.value) == false){
                why += "- Security code did not match.\n";
            }
        }
        if(why != ""){
            alert(why);
            return false;
        }
    }

    // Validate the Entered input aganist the generated security code function  
    function ValidCaptcha(){
        var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
        var str2 = removeSpaces(document.getElementById('txtInput').value);
        if (str1 == str2){
            return true;   
        }else{
            return false;
        }
    }

// Remove the spaces from the entered and generated code
    function removeSpaces(string){
        return string.split(' ').join('');
    }

1 个答案:

答案 0 :(得分:0)

1.我通过删除上面的checkform函数解决了这个问题 2.然后创建一个输入字段,并根据下面代码生成的txtCaptcha的输出对其进行验证。这样我的表单就会被我的原始验证器验证。 (没有冲突

<script type="text/javascript">
//Generates the captcha function   
    var a = Math.ceil(Math.random() * 9)+ '';
    var b = Math.ceil(Math.random() * 9)+ '';      
    var c = Math.ceil(Math.random() * 9)+ ''; 
    var d = Math.ceil(Math.random() * 9)+ ''; 
 var e = Math.ceil(Math.random() * 9)+ ''; 

 var code = a + b + c + d + e;
 document.getElementById("txtCaptcha").value = code;
  document.getElementById("txtCaptchaDiv").innerHTML = code;
var spryconfirm1 = new Spry.Widget.ValidationConfirm("spryconfirm1", "txtCaptcha");
</script>