Catalog Client script to handle the date

Venkatesh_Ramai
Tera Contributor

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;        

}

3 REPLIES 3

alan_lowrance
Mega Guru

You might have to do if (jsStartDate.getNumericValue() < jsToday.getNumericValue()) to compare them in millisecond values instead of text string dates.


Bharath40
Giga Guru

Thanks Bharath