Hi,
I'm trying to make a "validatior" for my forms - but for some reason, even where returning 'return false;' it still goes on to the next step :/
The JS code is:
The form is quite long winded.. but consists of:
I'm really stumped as to why this is happening - so any suggestions are MUCH welcomed!
TIA
Andy
I'm trying to make a "validatior" for my forms - but for some reason, even where returning 'return false;' it still goes on to the next step :/
The JS code is:
Code:
<script>
function Validator(theForm)
{
if (theForm.name_first_billing.value == "")
{
alert("Please enter a \"Billing First Name\".");
theForm.name_first_billing.focus();
return false;
}
if (theForm.name_last_billing.value == "")
{
alert("Please enter a \"Billing Last Name\".");
theForm.name_last_billing.focus();
return false;
}
if (theForm.address1_billing.value == "")
{
alert("Please enter a \"Billing Address\".");
theForm.address1_billing.focus();
return false;
}
if (theForm.city_billing.value == "")
{
alert("Please enter a \"Billing City\".");
theForm.city_billing.focus();
return false;
}
if (theForm.stateID_billing.value == "0")
{
alert("Please select a \"Billing State\".");
theForm.stateID_billing.focus();
return false;
}
if (theForm.zipcode_billing.value.length < 5)
{
alert("Please enter a \"Billing Zipcode\".");
theForm.zipcode_billing.focus();
return false;
}
if (theForm.phone_billing.value.length < 10)
{
alert("Please enter a \"Billing Phone Number\" that includes the area code.");
theForm.phone_billing.focus();
return false;
}
if (theForm.email.value == "")
{
alert("Please enter an \"Email Address\".");
theForm.email.focus();
return false;
}
if (BadEmail(theForm.email.value))
{
alert("The \"Email Address\" is not valid.");
theForm.email.focus();
return false;
}
if (theForm.name_first.value == "")
{
alert("Please enter a \"Ship To First Name\".");
theForm.name_first.focus();
return false;
}
if (theForm.name_last.value == "")
{
alert("Please enter a \"Ship To Last Name\".");
theForm.name_last.focus();
return false;
}
if (theForm.address1.value == "")
{
alert("Please enter a \"Ship To Address\".");
theForm.address1.focus();
return false;
}
if (theForm.city.value == "")
{
alert("Please enter a \"Ship To City\".");
theForm.city.focus();
return false;
}
if (theForm.stateID.value == "0")
{
alert("Please select a \"Shipping State\".");
theForm.stateID.focus();
return false;
}
if (theForm.zipcode.value.length < 5)
{
alert("Please enter a \"Ship To Zipcode\".");
theForm.zipcode.focus();
return false;
}
return (true);
}
</script>
The form is quite long winded.. but consists of:
Code:
<form class="formclass" method="post" id="form1" name="theForm" onsubmit="return Validator(this)" action="order.cgi">
...HTML forms etc
</form>
I'm really stumped as to why this is happening - so any suggestions are MUCH welcomed!
TIA
Andy