Hello,
I am very new to this so please excuse me if i do not use the correct terminology.
I have a function in my form that validates fields which does work.
However i want to add a function that will make sure that the email address field actually has an email address in it, not just any old characters.
I have found various bits of code on the internet but everytime i try to add another function to validate the email address none of the functions work.
Please see below my script.
This is from the HTML:
<form id="Litreqform" action="testlitreq.asp" method="post" name="Litreqform" onsubmit="return Litreqform_Validator(this)" style="z-index: 1; width: 955px; height: 672px; position: absolute; top: 863px; left: 20px">
This is from the Javascript:
<script language="javascript">
function Litreqform_Validator(theForm)
{
if (theForm.First_Name.value == "")
{
alert("Please enter a value for the \"First_Name\" field.");
theForm.First_Name.focus();
return (false);
}
if (theForm.Last_Name.value == "")
{
alert("Please enter a value for the \"Last_Name\" field.");
theForm.Last_Name.focus();
return (false);
}
if (theForm.Company_Name.value == "")
{
alert("Please enter a value for the \"Company_Name\" field.");
theForm.Company_Name.focus();
return (false);
}
if (theForm.Title.value == "")
{
alert("Please enter a value for the \"Title\" field.");
theForm.Title.focus();
return (false);
}
if (theForm.Address1.value == "")
{
alert("Please enter a value for the \"Address1\" field.");
theForm.Address1.focus();
return (false);
}
if (theForm.City.value == "")
{
alert("Please enter a value for the \"City\" field.");
theForm.City.focus();
return (false);
}
if (theForm.Postcode_Zip.value == "")
{
alert("Please enter a value for the \"Postcode/Zip\" field.");
theForm.Postcode_Zip.focus();
return (false);
}
if (theForm.Country.value == "")
{
alert("Please enter a value for the \"Country\" field.");
theForm.Country.focus();
return (false);
}
if (theForm.Phone.value == "")
{
alert("Please enter a value for the \"Phone\" field.");
theForm.Phone.focus();
return (false);
}
if (theForm.Fax.value == "")
{
alert("Please enter a value for the \"Fax\" field.");
theForm.Fax.focus();
return (false);
}
if (theForm.Email.value == "")
{
alert("Please enter a value for the \"Email\" field.");
theForm.Email.focus();
return (false);
}
return (true);
}
</script>
I am very new to this so please excuse me if i do not use the correct terminology.
I have a function in my form that validates fields which does work.
However i want to add a function that will make sure that the email address field actually has an email address in it, not just any old characters.
I have found various bits of code on the internet but everytime i try to add another function to validate the email address none of the functions work.
Please see below my script.
This is from the HTML:
<form id="Litreqform" action="testlitreq.asp" method="post" name="Litreqform" onsubmit="return Litreqform_Validator(this)" style="z-index: 1; width: 955px; height: 672px; position: absolute; top: 863px; left: 20px">
This is from the Javascript:
<script language="javascript">
function Litreqform_Validator(theForm)
{
if (theForm.First_Name.value == "")
{
alert("Please enter a value for the \"First_Name\" field.");
theForm.First_Name.focus();
return (false);
}
if (theForm.Last_Name.value == "")
{
alert("Please enter a value for the \"Last_Name\" field.");
theForm.Last_Name.focus();
return (false);
}
if (theForm.Company_Name.value == "")
{
alert("Please enter a value for the \"Company_Name\" field.");
theForm.Company_Name.focus();
return (false);
}
if (theForm.Title.value == "")
{
alert("Please enter a value for the \"Title\" field.");
theForm.Title.focus();
return (false);
}
if (theForm.Address1.value == "")
{
alert("Please enter a value for the \"Address1\" field.");
theForm.Address1.focus();
return (false);
}
if (theForm.City.value == "")
{
alert("Please enter a value for the \"City\" field.");
theForm.City.focus();
return (false);
}
if (theForm.Postcode_Zip.value == "")
{
alert("Please enter a value for the \"Postcode/Zip\" field.");
theForm.Postcode_Zip.focus();
return (false);
}
if (theForm.Country.value == "")
{
alert("Please enter a value for the \"Country\" field.");
theForm.Country.focus();
return (false);
}
if (theForm.Phone.value == "")
{
alert("Please enter a value for the \"Phone\" field.");
theForm.Phone.focus();
return (false);
}
if (theForm.Fax.value == "")
{
alert("Please enter a value for the \"Fax\" field.");
theForm.Fax.focus();
return (false);
}
if (theForm.Email.value == "")
{
alert("Please enter a value for the \"Email\" field.");
theForm.Email.focus();
return (false);
}
return (true);
}
</script>