Create JS Date objects from the user input and then you can use the 
greater-than operator.

function validateDates(f) {
   var returnVal = true;
   var objStartDate = new Date(f.startDate.value);
   var objStopDate = new Date(f.stopDate.value);
   if (objStartDate > objStopDate) {
      alert('You cannot stop before you start!");
      returnVal = false;
   }
   return returnVal;
}

This assumes that the user-input dates are date strings, e.g. "Aug 3, 1963". 
 Probably not too likely.  If the user-input dates are of the form dd/mm/yy or 
similar, you'll need to parse that into integers representing day, month, and 
year number (and know that the JS month is  0-based, i.e. December = 11).

You may want to back up your JS validation with server-side (CF) validation as 
well.

-David

On Friday, June 29, 2001 9:44 PM, Ali Awan [SMTP:[EMAIL PROTECTED]] wrote:
> I apologize for asking a non-cf question on here, but hey maybe there's a CF
> solution to it.
> I have a page where a user enters two dates in a form.  A Start Date and an
> End Date, I want to write a Javascript Validation function that compares the
> two dates to make sure that the End Date is not earlier than the Star Date.
> Does any one know of a good way to achieve this?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to