Catalog Client script to handle the date

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 07:22 AM
Hi Guys,
I am stuck with a script which is pretty straightforward and its basically a Catalog Client Script used in one of the Catalogue item to handle the Startdate and enddate fields
The issue is that even though the user is inputting the valid dates for the End date, its throwing the alert 'End date cannot be before start date!'
Please can someone tell me whats wrong with the script.
function onSubmit() {
var jsStartDate = new Date(g_form.getValue('travel_start'));
var jsEndDate = new Date(g_form.getValue('travel_end'));
var jsToday = new Date();
if (jsStartDate < jsToday) {
alert(getMessage('Start date cannot be before today!'));
return false;
}
if (jsEndDate < jsStartDate) {
alert(getMessage('End date cannot be before start date!'));
return false;
}
return true;
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 07:36 AM
You might have to do if (jsStartDate.getNumericValue() < jsToday.getNumericValue()) to compare them in millisecond values instead of text string dates.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 07:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 04:30 AM
Thanks Bharath