我正在用单选按钮和复选框创建一个表单。我想用javascript onsubmit和php验证表单。为了让php工作,我必须在名称中使用[]来写复选框和单选按钮(例如)
我搜索了其他主题,看到我可以为单选按钮设置一个默认检查值,以避免人们可能不会选择一个值。没关系。
但是,我还需要确保人员检查不超过3个复选框。这是无法完成的
var count = 0;
for (x=0; x
if (document.fic_rec.rec_genres[x].checked){
count++;
}
}
if (count==0){
rec_error += "at least 1 genre; ";
}
else if (count>3){
rec_error += "no more than 3 genres; ";
}我收到一个错误,说“无法读取未定义的属性'长度'
我的HTML代码如下所示:
Action/Adventure
Alternative realityAU History
AU Universe
等等帮帮我!谢谢!!