我不明白我在這裏做錯了什麼....幾乎所有的嘗試都是在未經驗證的情況下提交表單。我不知道是什麼原因導致這個問題在這裏工作了4個小時,每次我點擊提交按鈕,它會直接提交成功的頁面...任何人都可以幫助我嗎?表單驗證不起作用,對於未經驗證提交的gettting
<script type ="text/javascript">
function validate(){
if(document.orderForm.firstName.value==""){
document.getElementById('errors').innerHTML = "Please Enter a First Name";
document.orderForm.fistName.focus();
return (false);
}
if(document.orderForm.lastName.value == ""){
document.getElementById('errors').innerHTML = "Please Enter a Last Name";
document.orderForm.lastName.focus();
return (false);
}
if(document.orderForm.address.value == ""){
document.getElementById('errors').innerHTML = "Please Enter a address");
document.orderForm.address.focus();
return (false);
}
if(document.orderForm.city.value == ""){
document.getElementById('errors').innerHTML = "Please Enter a City");
document.orderForm.city.focus();
return (false);
}
if(document.orderForm.postalCode.value == "" ||
document.orderForm.postalCode.value.length != 6){
document.getElementById('errors').innerHTML = "Please Enter a correct PostalCode");
document.orderForm.postalCode.focus();
return (false);
}
if(document.orderForm.province.value == "Select"){
document.getElementById('errors').innerHTML = "Please Select your province")
return (false);
}
if(document.orderForm.widget1qty.value == "0" || document.orderForm.widget1qty.value == "" &&
document.orderForm.widget2qty.value == "0" || document.orderForm.widget2qty.value == "" &&
document.orderForm.widget2qty.value == "0" || document.orderForm.widget2qty.value == ""){
document.getElementById('errors').innerHTML = "Please Select at least one item")
return (false);
}
else
{
return(true);
}
}
</script>
<form name="orderForm" method="POST" action="processForm.html" onSubmit="return validate();">
看看這個[鏈接](http://www.w3schools.com/js/js_form_validation.asp)用於表單驗證。 – 2014-10-28 05:23:59
你的validate函數中有幾個語法錯誤,比如'document.getElementById('errors')。innerHTML =「請輸入一個地址」);',在這個結尾處有括號。 – Ravi 2014-10-28 05:32:29
修正了錯誤,仍然不能正常工作 – 2014-10-28 05:41:18