MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started page 105

Building coldfusion mx applications
Table of Contents

Advertisement

Another reason that rule 6 requires JavaScript scripting is that it tests the values of more than one
field in a single edit. You must ensure that the return date field is greater than departure date field.
To do this, you add a JavaScript function to validate the trip date range entered, and specify the
function on the
onValidate
function validateTripDateRange(oForm, oTag, dateString)
{
/*
parameters: oForm, oTag, dateString
returns: boolean
oForm is the CFForm object. All onvalidate calls pass this argument.
This function ignores it.
oTag is the CFForm current tag object. All onvalidate calls pass this
argument.
This function ignores it.
dateString is the value of the current tag object. It should be a date
passed as a string in the following
format: MM/DD/YYYY. This means that months and days require leading zeros!!
Returns True if the date passed is a future date greater than the departure
date
Returns False if the date passed is NOT a future date greater than departure
date.
*/
//Edit to make sure that Return date is Later than departure date.
var returnDateString;
//First check to see if the departure Date is a valid future date
if (isitFutureDate(oForm, oTag, dateString) == false)
return false;
var departureDate = new Date(dateString.substring(6,10),
dateString.substring(0,2)-1,
dateString.substring(3,5));
returnDateString = document.forms(0).item("returnDate").value;
var returnDate = new Date(returnDateString.substring(6,10),
returnDateString.substring(0,2)-1,
returnDateString.substring(3,5));
if (departureDate < returnDate)
return true;
else
return false;
}
The important point about the preceding JavaScript is that you can use two functions,
and
isitFutureDate
trip date range is valid, respectively.
attribute of the
validateTripDateRange
Developing code to validate data and enforce business rules
returnDate cfinput
, to verify whether a date is in the future and the
tag:
105

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?

This manual is also suitable for:

Coldfusion mx

Table of Contents