sunnyview
08-28-2002, 07:40 AM
Thanks to glenngv and whammy with your previous help with this script. It's working fine now, except that it validates from the bottom upwards!
I have no idea how to correct this, except by reversing the order of the validation within the script.
I would appreciate a detailed reply, as I am new to JavaScript and am currently struggling. Thanks in anticipation.
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
//Airport Drop-off --- Airport Pick-up --- Airport Pick-up
//Airport Drop-off --- Airport Pick-up --- Airport Pick-up
if (document.booking.pickup[1].checked)
{
if (!document.booking.Fltno.value)
{
Message = "Please enter your flight number.";
FocusField = "Fltno";
Proceed = 0;
}
}
if (document.booking.pickup[1].checked)
{
if (!document.booking.pickuptime.value)
{
Message = "Please enter your scheduled NZ pick-up time.";
FocusField = "pickuptime";
Proceed = 0;
}
}
if (document.booking.pickup[1].checked)
{
if (!document.booking.pickupdate.value)
{
Message = "Please enter your scheduled NZ pick-up date.";
FocusField = "pickupdate";
Proceed = 0;
}
}
if (document.booking.pickup[1].checked)
{
if (!document.booking.group.value)
{
Message = "Please enter your scheduled NZ pick-up date.";
FocusField = "group";
Proceed = 0;
}
}
//Airport Drop-off --- Airport Drop-off - Airport Drop-off
//Airport Drop-off --- Airport Drop-off - Airport Drop-off
if (document.booking.dropoff[1].checked)
{
if (!document.booking.Fltno2.value)
{
Message = "Please enter your return flight number.";
FocusField = "Fltno2";
Proceed = 0;
}
}
if (document.booking.dropoff[1].checked)
{
if (!document.booking.dropofftime.value)
{
Message = "Please enter your scheduled NZ drop-off time.";
FocusField = "dropofftime";
Proceed = 0;
}
}
if (document.booking.dropoff[1].checked)
{
if (!document.booking.dropoffdate.value)
{
Message = "Please enter your scheduled NZ drop-off date.";
FocusField = "dropoffdate";
Proceed = 0;
}
}
//Renters Details --- Renters Details --- Renters Details
//Renters Details --- Renters Details --- Renters Details
if (!document.booking.Surname.value)
{
Message = "Please enter your Surname.";
FocusField = "Surname";
Proceed = 0;
}
if (!document.booking.Firstname.value)
{
Message = "Please enter your Firstname.";
FocusField = "Firstname";
Proceed = 0;
}
if (!document.booking.DOB.value)
{
Message = "Please enter your Date of Birth.";
FocusField = "DOB";
Proceed = 0;
}
if (!document.booking.Homeaddress.value)
{
Message = "Please enter your Home Address.";
FocusField = "Homeaddress";
Proceed = 0;
}
if (!document.booking.driversln.value)
{
Message = "Please enter your Driver's Licence No.";
FocusField = "driversln";
Proceed = 0;
}
if (!document.booking.issuing.value)
{
Message = "Please enter the Issuing Country or State of your Driver's Licence.";
FocusField = "issuing";
Proceed = 0;
}
if (!document.booking.expiry.value)
{
Message = "Please enter the expiry date of your Driver's Licence.";
FocusField = "expiry";
Proceed = 0;
}
if (Proceed == 1)
{
alert("The form has been successfully completed.");
return true;
}
else
{
alert( Message );
if (FocusField != "")
{
eval("document.booking." + FocusField + ".focus()");
}
return false;
}
}
//-->
</script>
I have no idea how to correct this, except by reversing the order of the validation within the script.
I would appreciate a detailed reply, as I am new to JavaScript and am currently struggling. Thanks in anticipation.
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
//Airport Drop-off --- Airport Pick-up --- Airport Pick-up
//Airport Drop-off --- Airport Pick-up --- Airport Pick-up
if (document.booking.pickup[1].checked)
{
if (!document.booking.Fltno.value)
{
Message = "Please enter your flight number.";
FocusField = "Fltno";
Proceed = 0;
}
}
if (document.booking.pickup[1].checked)
{
if (!document.booking.pickuptime.value)
{
Message = "Please enter your scheduled NZ pick-up time.";
FocusField = "pickuptime";
Proceed = 0;
}
}
if (document.booking.pickup[1].checked)
{
if (!document.booking.pickupdate.value)
{
Message = "Please enter your scheduled NZ pick-up date.";
FocusField = "pickupdate";
Proceed = 0;
}
}
if (document.booking.pickup[1].checked)
{
if (!document.booking.group.value)
{
Message = "Please enter your scheduled NZ pick-up date.";
FocusField = "group";
Proceed = 0;
}
}
//Airport Drop-off --- Airport Drop-off - Airport Drop-off
//Airport Drop-off --- Airport Drop-off - Airport Drop-off
if (document.booking.dropoff[1].checked)
{
if (!document.booking.Fltno2.value)
{
Message = "Please enter your return flight number.";
FocusField = "Fltno2";
Proceed = 0;
}
}
if (document.booking.dropoff[1].checked)
{
if (!document.booking.dropofftime.value)
{
Message = "Please enter your scheduled NZ drop-off time.";
FocusField = "dropofftime";
Proceed = 0;
}
}
if (document.booking.dropoff[1].checked)
{
if (!document.booking.dropoffdate.value)
{
Message = "Please enter your scheduled NZ drop-off date.";
FocusField = "dropoffdate";
Proceed = 0;
}
}
//Renters Details --- Renters Details --- Renters Details
//Renters Details --- Renters Details --- Renters Details
if (!document.booking.Surname.value)
{
Message = "Please enter your Surname.";
FocusField = "Surname";
Proceed = 0;
}
if (!document.booking.Firstname.value)
{
Message = "Please enter your Firstname.";
FocusField = "Firstname";
Proceed = 0;
}
if (!document.booking.DOB.value)
{
Message = "Please enter your Date of Birth.";
FocusField = "DOB";
Proceed = 0;
}
if (!document.booking.Homeaddress.value)
{
Message = "Please enter your Home Address.";
FocusField = "Homeaddress";
Proceed = 0;
}
if (!document.booking.driversln.value)
{
Message = "Please enter your Driver's Licence No.";
FocusField = "driversln";
Proceed = 0;
}
if (!document.booking.issuing.value)
{
Message = "Please enter the Issuing Country or State of your Driver's Licence.";
FocusField = "issuing";
Proceed = 0;
}
if (!document.booking.expiry.value)
{
Message = "Please enter the expiry date of your Driver's Licence.";
FocusField = "expiry";
Proceed = 0;
}
if (Proceed == 1)
{
alert("The form has been successfully completed.");
return true;
}
else
{
alert( Message );
if (FocusField != "")
{
eval("document.booking." + FocusField + ".focus()");
}
return false;
}
}
//-->
</script>