【发布时间】:2012-02-16 18:55:50
【问题描述】:
我正在尝试检查用户输入是否选中了 greater than 2 和 less than 4 复选框。
我必须在提交表单之前进行这项检查。
虽然我使用 AlloyUI 进行客户端验证。你可以帮助我使用香草 javascript。
请帮我写代码...
<% for(loop here which generates more than one checkbox) { %>
<form name=".." method=".." action=".." onSubmit="return checkBox();">
<input type="checkbox" id=".." name=".."/>
</form>
%>
我的 javascript
function checkBox(){
alert("start");
var total = 0;
var max = form.checkcompare.length;
alert(max);
for(var idx = 0; idx < max; idx++)
{
if(eval("document.compareform.checkcompare[" + idx + "].checked") == true)
{
alert("checking");
total += 1;
}
}
if (total==2 || total==4)
{
/* document.compareform.submit(); */
alert("success");
}
else
{
alert('Select minimum of 2 or maximum of 4 Estimates');
}
//alert("You selected " + total + " boxes.");
}
它不起作用..有人可以帮忙..谢谢
【问题讨论】:
标签: javascript validation checkbox