如果单击“是”按钮,我要做的是重定向到新页面。如果他们单击“否”,我已经设置了提示。但是,需要填写一个表格(姓名和电子邮件)才能使用。如果他们没有填写这些详细信息,我希望出现一个提示,告诉用户他们需要填写它们才能继续。
我对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: projects@spearheadmining.com to discuss your options for project submittal!");
}
return false;
});