Developing code to validate data and enforce business rules
105
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
attribute of the
returnDate
cfinput
tag:
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,
isitFutureDate
and
validateTripDateRange
, to verify whether a date is in the future and the
trip date range is valid, respectively.
Содержание COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 30: ...30 Chapter 2 CFML Basics...
Страница 36: ...36 Chapter 3 Database Fundamentals...
Страница 48: ......
Страница 76: ...76 Chapter 6 Lesson 2 Writing Your First ColdFusion Application...
Страница 134: ...134 Index...