sunnyview
09-07-2002, 08:00 AM
I have 2 forms on 1 html page, each with their own submit button.
Each form has its own javascript for validation of the fields.
Is there a way I can identify which javascript belongs to which form? because at present validation is taking place for both forms.
Could be something to do with function names, but i'm not sure. Here is the script for the first form:
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
//Method of Payment --- Method of Payment --- Method of Payment
//Method of Payment --- Method of Payment --- Method of Payment
if (!document.enquiry.Date_required_to.value)
{
Message = "Please enter the DATE REQUIRED TO.";
FocusField = "Date_required_to";
Proceed = 0;
}
if (!document.enquiry.Date_required_from.value)
{
Message = "Please enter the DATE REQUIRED FROM.";
FocusField = "Date_required_from";
Proceed = 0;
}
if (!document.enquiry.Your_telephone_number.value)
{
Message = "Please enter YOUR TELEPHONE NUMBER.";
FocusField = "Your_telephone_number";
Proceed = 0;
}
if (!document.enquiry.Your_email_address.value)
{
Message = "Please enter YOUR EMAIL ADDRESS.";
FocusField = "Your_email_address";
Proceed = 0;
}
if (!document.enquiry.Your_Name.value)
{
Message = "Please enter YOUR NAME.";
FocusField = "Your_Name";
Proceed = 0;
}
//alert
if (Proceed == 1)
{
alert("The enquiry has been successfully completed.");
return true;
}
else
{
alert( Message );
if (FocusField != "")
{
eval("document.enquiry." + FocusField + ".focus()");
}
return false;
}
}
//-->
</script>
THE FORM PART:
<FORM ACTION="http://homepages.paradise.net.nz/cgi-bin/mailto"
METHOD="POST" name="enquiry" onsubmit="return ProcessForm()" target="_top">
etc ....
<input name=First type=submit value="Send Enquiry">
Each form has its own javascript for validation of the fields.
Is there a way I can identify which javascript belongs to which form? because at present validation is taking place for both forms.
Could be something to do with function names, but i'm not sure. Here is the script for the first form:
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
//Method of Payment --- Method of Payment --- Method of Payment
//Method of Payment --- Method of Payment --- Method of Payment
if (!document.enquiry.Date_required_to.value)
{
Message = "Please enter the DATE REQUIRED TO.";
FocusField = "Date_required_to";
Proceed = 0;
}
if (!document.enquiry.Date_required_from.value)
{
Message = "Please enter the DATE REQUIRED FROM.";
FocusField = "Date_required_from";
Proceed = 0;
}
if (!document.enquiry.Your_telephone_number.value)
{
Message = "Please enter YOUR TELEPHONE NUMBER.";
FocusField = "Your_telephone_number";
Proceed = 0;
}
if (!document.enquiry.Your_email_address.value)
{
Message = "Please enter YOUR EMAIL ADDRESS.";
FocusField = "Your_email_address";
Proceed = 0;
}
if (!document.enquiry.Your_Name.value)
{
Message = "Please enter YOUR NAME.";
FocusField = "Your_Name";
Proceed = 0;
}
//alert
if (Proceed == 1)
{
alert("The enquiry has been successfully completed.");
return true;
}
else
{
alert( Message );
if (FocusField != "")
{
eval("document.enquiry." + FocusField + ".focus()");
}
return false;
}
}
//-->
</script>
THE FORM PART:
<FORM ACTION="http://homepages.paradise.net.nz/cgi-bin/mailto"
METHOD="POST" name="enquiry" onsubmit="return ProcessForm()" target="_top">
etc ....
<input name=First type=submit value="Send Enquiry">