我想檢查用戶輸入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