Adding days to date field in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2016 04:43 AM
Hi Guys
I have the following Client script, but I want to add 2 days to the one variable called 'today'. Any ideas?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var reqDate = new Date(newValue);
var today = new Date(); //add 2 days to this var
if(reqDate <= today){
alert('Date must not be in the past and at least 2 days from now');
g_form.setValue('u_excepted', '');
}
}
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2016 04:51 AM
Hi Rudi,
Doing this on the client side is somewhat unreliable. Here's a collection of useful time/date scripts that can help (one of which is to add date/time.)
Client Script Date/Time Functions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2016 05:55 AM
Hi ctomasi
Okay, im getting this to work. The only thing I need from this is to get the value from today's date and not the selected date like in this line:
var cdt = g_form.getValue('some_date'); //Choose the field to add time from
Then I need to compare it and get a result.
The end result will be not to be able to select a date in the past up until 2 days from now. I hope it makes sense.. Am I missing something?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2016 06:00 AM
Hi Rudi,
The other functions in that linked script should do the trick for you. Let the user pick a date, then use an onChange client script to call the appropriate date comparison function.