我想检查用户输入greater than 2
和less than 4
复选框被选中。如何检查< 2 and > 4在javascript中的复选框
我必须在表单提交之前做这个检查。
尽管我使用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.");
}
它不是working..can有人help..Thanks
我有它的权利在我的代码。形式,然后循环内。 我尝试了你的代码,表单也没有任何提醒。你能帮我一个好心情吗?如果可以的话,请发送我的整个HTML。因为我必须改变AUI ...这应该帮助我gr8交易。 – 2012-02-16 19:21:55