2011-12-16 90 views
1

我用兩個複選框創建了驗證。如何一次兩次驗證兩次結果

兩個驗證與JavaScript的

工作的罰款讓我告訴你我的代碼

javascipt的

function Validation_agree(){ 
    if(document.form1.agreed1.checked==false) 
    { 
     $(".agreement_main").show(); 
     return false 
    }else{ 
     $(".agreement_main").hide(); 
    } 

    if(document.form1.agreed2.checked==false) 
    { 
     $(".agreement_terms").show(); 
     return false 
    }else{ 
     $(".agreement_terms").hide(); 
    } 
} 

形式就像

<div class="checkme"> 
    <label><input type="checkbox" value="" name="agreed1" />I have discussed all of the order details above and the customer is happy to proceed</label> 
<br /> 
    <div class="alert agreement_main" style="display:none;">Please confirm you have informed the customer of the T&amp;Cs</div> 
</div> 

<div class="redNote"> 
<label><input type="checkbox" value="" name="agreed2" />I have informed the customer where they can find the T&C’s on the BT.com website</label></p> 
<div class="alert agreement_terms" style="display:none;">Please confirm you have informed the customer of the T&amp;Cs</div> 
</div> 


<input type="submit" value="submit order" /></div> 
</form>      

的問題是。其中一個正在處理另一個
當按提交按鈕顯示第一個驗證錯誤消息。我想提出兩個驗證檢查一次

任何一個可以幫助我,請 在此先感謝

+0

我面臨類似的問題,我的應用程序之一:( – Muhammed 2011-12-16 17:10:25

回答

3

下面的代碼可能爲你工作。

function Validation_agree(){  
var isValid = true; 
if(document.form1.agreed1.checked==false)  
    {   
     $(".agreement_main").show();   
     isValid = false; 
    }else 
    {   
     $(".agreement_main").hide();  
    }   
    if(document.form1.agreed2.checked==false)  
    {   
     $(".agreement_terms").show();   
     isValid = false;  
    }else{   
     $(".agreement_terms").hide();  
     } 
     return isValid; 
}