这是我的代码:
<script>
function validate(form) {
fail = validate_department(form);
if (fail == "") {
return true;
} else {
alert(fail);
return false;
}
}
</script>
<script>
function validate_department(form) {
if(!(form.operations.checked == true) && !(form.marketing.checked == true) && !(form.training.checked == true)){ return "You must enter at least one of the following: marketing, training, or operations.\n";
}
return "";
}
</script>
<form method="post" action="checkbox.php" onSubmit="return validate(this)">
<input type="checkbox" name="operations" value="operations" /> Operations <br>
<input type="checkbox" name="marketing" value="marketing" /> Marketing <br>
<input type="checkbox" name="training" value="training" /> Training
<input id="submit" type="submit" name="submit" value="Signup" />
</form>
如果我不检查任何内容,我想收到一条消息,告诉我我必须至少检查一个。