我有一个带有这样的复选框的表单:
<input type="checkBox" name="type[]" value="1" />Fast Food<br> <input type="checkBox" name="type[]" value="2" />Table Service<br> <input type="checkBox" name="type[]" value="3" />Cafeteria<br>
$type=$_POST['type']; echo "types are:"; for ( $counter = 0; $counter < sizeof($type); $counter += 1) { echo "<br>".$type[$counter]; }
但我的JavaScript不起作用:
var f = document.addform; for (var i=0;i<f.type.length;i++){ if(f.type[i].checked==true){ break; } if(i==(f.type.length-1)){ alert("No categories entered!"); valid=false; } }
但是,如果我拿走括号:
<input type="checkBox" name="type" value="1" />Fast Food<br>
然后PHP不起作用,但javascript确实如此.
这里发生了什么?我应该用什么?
谢谢.