checkboxlist的Javascript验证&;文本框在一起
请使用下面的代码进行帮助,只有文本框验证有效。复选框验证无效。 如果我只在代码中放置复选框列表验证,它会工作,但文本框和复选框列表一起不工作checkboxlist的Javascript验证&;文本框在一起,javascript,asp.net,Javascript,Asp.net,请使用下面的代码进行帮助,只有文本框验证有效。复选框验证无效。 如果我只在代码中放置复选框列表验证,它会工作,但文本框和复选框列表一起不工作 function Validate() { var Branches = 3 var CHK = document.getElementById("<%=CheckBoxList1.ClientID%>"); var checkbox = CHK.getElementsByTagName("inp
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>
函数验证(){
var分支=3
var CHK=document.getElementById(“”);
var checkbox=CHK.getElementsByTagName(“输入”);
var计数器=0;
var CollegeName=document.getElementById(“”).value;
var Location=document.getElementById(“”).value;
if(CollegeName==“”)
{
警告(“请输入学院名称”);
返回false;
}
如果(位置==“”)
{
警报(“请输入位置”);
返回false;
}
对于(变量i=0;i计数器){
警报(“请至少选择“+分支机构+”分支机构”);
返回false;
}
返回true;
}
您在和计数器
变量中得到了什么?抱歉,代码是正确的,但必须用变量替换。我忘了。我正在使用计数器变量与分支变量进行比较,在“if(至少>counter)”处使用了alterable变量代替分支变量。