我的表單目前檢查兩個電子郵件字段以確保它們匹配。我還想確保兩個電子郵件字段都不爲空,並且複選框已被選中。我一直在搜尋例子,似乎沒有什麼可以做的。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>