2012-04-16 40 views
1

我試圖驗證2只複選框列出了我的usercontrole.after一些谷歌上搜索我能夠驗證我的第一個複選框list.code下面如何使用jQuery驗證多個下拉列表?

<script language="javascript" type="text/javascript"> 

function ValidateChkList(source, arguments) { 

    arguments.IsValid = IsCheckBoxChecked() ? true : false; 
} 
function IsCheckBoxChecked() { 
    var isChecked = false; 
    var list = document.getElementById('<%= cblJobType.ClientID %>'); 

    if (list != null) { 
     for (var i = 0; i < list.rows.length; i++) { 
      for (var j = 0; j < list.rows[i].cells.length; j++) { 
       var listControl = list.rows[i].cells[j].childNodes[0]; 
       if (listControl.checked) { 
        isChecked = true; 
       } 
      } 
     } 
    } 
    return isChecked; 
} 

<asp:CustomValidator ID="cvJobType" ClientValidationFunction="ValidateChkList" CssClass="error" 
             SetFocusOnError="True" ValidationGroup="step1" runat="server"></asp:CustomValidator> 

給定,但是當我嘗試同樣在第二個都沒有任何working.can一個幫助我..

回答

0

與嘗試:

function ValidateChkList(source, arguments) { 

    arguments.IsValid = IsCheckBoxChecked() ? true : false; 
} 
function IsCheckBoxChecked(id) { 
    var isChecked = false; 
    var list = document.getElementById(id); 

    if (list != null) { 
     for (var i = 0; i < list.rows.length; i++) { 
      for (var j = 0; j < list.rows[i].cells.length; j++) { 
       var listControl = list.rows[i].cells[j].childNodes[0]; 
       if (listControl.checked) { 
        isChecked = true; 
       } 
      } 
     } 
    } 
    return isChecked; 
} 

IsCheckBoxChecked('<%= cblJobType.ClientID %>'); 
IsCheckBoxChecked('<%= second_list.ClientID %>'); 
IsCheckBoxChecked('<%= third_list.ClientID %>');