i have a form with checkboxes like this:
<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>
when i use the brackets in the name (type[]), my php works:
$type=$_POST['type'];
echo "types are:";
for ( $counter = 0; $counter < sizeof($type); $counter += 1) {
echo "<br>".$type[$counter];
}
but my javascript doesn't work:
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;
}
}
however, if i take away the brackets:
<input type="checkbox" name="type" value="1" />Fast Food<br>
then the PHP doesn't work but the javascript does.
what's going on here? what should i use?
thanks.