一起对checkboxlist& textbox进行Javascript验证

时间:2014-01-30 04:37:34

标签: javascript asp.net

请帮助下面的代码,只有文本框验证工作。检查框验证不起作用。 如果我只在我的代码中放置了checkboxlist验证,它可以工作,但是文本框和复选框列表一起不起作用。

function Validate() {
        var Branches = 3
        var CHK = document.getElementById("<%=CheckBoxList1.ClientID%>");
        var checkbox = CHK.getElementsByTagName("input");
        var counter = 0;
        var CollegeName = document.getElementById('<%=txtCollegeName.ClientID %>').value;
        var Location = document.getElementById('<%=txtLocation.ClientID %>').value;
            if (CollegeName == "")
            {
                alert("Please Enter College Name");
                return false;
            }
            if (Location == "")
            {
                alert("Please Enter Location");
                return false;
            }
    for (var i = 0; i < checkbox.length; i++) {
        if (checkbox[i].checked) {
            counter++;
        }
    }
    if (atLeast > counter) {
        alert("Please select atleast " + Branches + " Branches");
        return false;
    }              
    return true;
}
</script>

0 个答案:

没有答案
相关问题