2011-10-19 262 views
1

我創建了驗證碼驗證程序,但它覆蓋了驗證整個表單並提交它的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(''); 
    } 

回答

0

1.I通過去除上述 2. checkform函數然後創建一個輸入字段和驗證它抵抗由下面的代碼所產生的所述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>