0
JavaScript未驗證「優惠券」表單上的字段。如果一個字段留空,它應該將它們發送到錯誤頁面。現在,您可以將姓氏和名字留空,然後輸入您的電子郵件地址以獲得優惠券。只有電子郵件地址表單正在驗證。以下是我目前擁有的代碼。該表格是代碼的一半左右的優惠券形式。JavaScript驗證不能在多種形式的頁面上工作
<script type="text/javascript">
function validate-coupon-form()
{
if (document.subscribeForm.First_Name.value == "")
{
alert("Please enter your First Name");
document.subscribeForm.First_Name.focus();
return false;
}
if (document.subscribeForm.Last_Name.value == "")
{
alert("Please enter your Last Name");
document.subscribeForm.Last_Name.focus();
return false;
}
if (document.subscribeForm.Email Address.value == "")
{
alert("Please enter your Email Address");
document.subscribeForm.Email Address.focus();
return false;
}
return(true);
}
</script>
<div class="namath-coupon-form-header">
<form class="namath-coupon-form" action="http://cl.exct.net/subscribe.aspx?lid=7549071" name="subscribeForm" method="post" onSubmit="return validate-coupon-form();">
<input type="hidden" name="thx" value="http://www.namathproducts.com/get-coupons-thank-you">
<input type="hidden" name="err" value="http://www.namathproducts.com/get-coupons-error">
<input type="hidden" name="MID" value="10692030">
<input type="hidden" name="Email Type" value="HTML" checked>
<input type="hidden" name="BU_Namath" value="TRUE" checked>
<input type="hidden" name="SubAction" value="sub_add_update" checked>
<label for="FirstName">
<span>First Name *</span>
<input type="text" class="required" name="First_Name" id="FirstName" >
</label><br>
<label for="LastName">
<span>Last Name *</span>
<input type="text" class="required" name="Last_Name" id="LastName" >
</label><br>
<label for="EmailAddress">
<span>Email *</span>
<input type="text" class="required" name="Email Address" id="EmailAddress" placeholder="[email protected]" >
</label><br>
<label>
<span> </span>
<input type="submit" class="button" name="Submit" value="GET COUPON">
</label>
</form>
</div>
頁眉和頁腳附近的表單正在驗證中。
任何幫助,將不勝感激!
您應該將代碼降低到顯示問題的最小值,例如成千上萬行的庫代碼被添加,但是這個函數並沒有使用它們中的任何一個。 – RobG