如果單擊「是」按鈕,我正在嘗試執行的操作是重定向到新頁面。如果點擊「否」,我已經設置了提示。但是,有一個表單(姓名和電子郵件)需要填寫才能運行。如果他們沒有填寫這些詳細信息,我想提示一個提示,告訴用戶他們需要填寫它們才能繼續。Javascript:重定向到基於單選按鈕選項的新頁面
我相當新的JavaScript,所以任何提示或解釋將不勝感激。
下面是HTML代碼
<input type="radio" name="radio" id="yes"><strong>Yes, I agree.</strong>
<br>
<input type="radio" name="radio" id="no" checked="checked"><strong>No, I do not agree. </strong><br>
<br>
If you agree, please enter your full name and email address in the spaces below and press submit.
<br>
<form> Full Name:<input type="text" name="fullname"></form>
<br>
<form> Email Address:<input type="text" name="email"></form>
<br>
<br>
<form action="endPage.jsp" id="form">
<input type="submit" id="submit" value="Submit" name="submit" />
</form>
和JavaScript代碼
var submitBtn = document.getElementById("submit");
var termsChk = document.getElementById("yes");
var formFrm = document.getElementById("emailField");
var formFrm = document.getElementById("nameField");
submitBtn.addEventListener("click", function() {
if (termsChk.checked === true && formFrm)
{
alert("Checked!");
formFrm.submit();
} else {
alert("Please Contact Spearhead Mining Corporation: [email protected] to discuss your options for project submittal!");
}
return false;
});
顯示錶單的代碼。顯示「已設置」提示的代碼。 – acdcjunior