我的表单目前检查两个电子邮件字段以确保它们匹配。我还想确保两个电子邮件字段都不为空,并且复选框已被选中。我一直在搜寻例子,似乎没有什么可以做的。Javascript表单验证(多个条件)
任何帮助将不胜感激。
<form action="" method="post" name="submission" onsubmit="return checkEmail(this);">
<label for="email">Email</label>
<input id="email" maxlength="55" name="email" type="text" value="<?=htmlspecialchars($_POST["email"]) ?>" /><br/>
<label for="emailconfirm">Confirm email address</label>
<input id="emailconfirm" maxlength="55" name="emailconfirm" type="text" value="<?=htmlspecialchars($_POST["emailconfirm"]) ?>" /><br/>
<label for="checksign">By completing this form, you agree to the terms and conditions above. If you do not agree to these terms, your application will not be considered.</label>
<input class="check" id="checksign" name="checksign[]" type="checkbox" value="Yes" />
</form>
<script type="text/javascript" language="JavaScript">
function checkEmail(theForm) {
if (theForm.email.value != theForm.emailconfirm.value)
{
alert('E-mail addresses do not match.');
return false;
} else {
return true;
}
}
</script>