我知道网上有很多帖子,我都试过了,但还是不行,请帮忙。我想确保至少选择了一个程序。我检查了控制台,但没有错误,还说调试器未激活。
JavaScript:
function validateForm() {
if (document.getElementById('cfname').value === '') {
document.getElementById('errcfname').innerHTML = "Please enter firstname";
return false;
}
if (document.enrollment.clname.value == "") {
document.getElementById('errclname').innerHTML = "Please enter lastname";
clname.focus();
return false;
}
if(validateRadio (document.getElementsByName('gender'))) {
return true;
} else {
document.getElementById('errgender').innerHTML = "Please specify gender";
return false;
}
var chk = document.getElementsByName('program[]');
var len = chk.length;
var checked = false;
for(i=0;i<len;i++) {
if(chk[i].checked) {
checked=true;
break;
}
}
if (!checked) {
document.getElementById('errpgm').innerHTML = "Please specify program";
return false;
}
}
return true;
}
function validateRadio(radios) {
for (i = 0; i < radios.length; ++ i) {
if (radios[i].checked)
return true;
}
return false;
}
function validate(id,error) {
var value = document.getElementById(id).value;
var err = document.getElementById(error);
if(!value) {
err.innerHTML = "*required";
} else {
err.innerHTML = "*";
}
}