| Normally, if you require the user to fill in certain fields on your form, the fields are not checked until the form's data is sent to the file server by clicking the SUBMIT button. The FormMail script, running on the server, checks to see if the required fields have been filled in, and, if not, returns an error message to the user.
To speed up the process, JavaScript can be used to check the required fields before the form's data is sent to the server:
<"script language="JavaScript">
<!--
function infoform_Validator(theForm)
{
if (theForm.realname.value == "")
{
alert("Please enter your first and last name.");
theForm.realname.focus();
return (false);
}
if (theForm.Address.value == "")
{
alert("Please enter your address.");
theForm.Address.focus();
return (false);
}
if (theForm.City.value == "")
{
alert("Please enter your city.");
theForm.City.focus();
return (false);
}
if (theForm.State.value == "")
{
alert("Please enter your state (if applicable).");
theForm.State.focus();
return (false);
}
if (theForm.Zip_Code.value == "")
{
alert("Please enter your zip code.");
theForm.Zip_Code.focus();
return (false);
}
if (theForm.Telephone.value == "")
{
alert("Please enter your telephone number.");
theForm.Telephone.focus();
return (false);
}
return (true);
}
//-->
</script>
To activate this script on submission, we have to add the following codes to the form: <FORM METHOD="POST" ACTION="http://www.myURL.com/cgi-bin/FormMail.pl" onsubmit="return infoform_Validator(this)" NAME="infoform">
This page was last modified |