Skip to main content
Participant
September 22, 2023
Question

Auto calculate dates and populate fields

  • September 22, 2023
  • 1 reply
  • 758 views

I am creating a form the give dates  they can use security authentication codes given to them

There are  28 day codes, 60 week codes and 5 year codes.  I created a drop down box 

with their selection (i.e., 28, 60, etc).  Is there a way to create separate fields that give

the start and end date of each type selected?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 22, 2023

The end date can be calculated based on the start date and that period, but what is the start date? The current date? A date the user enters? Something else?

 

Participant
September 22, 2023

Date entered by the user

try67
Community Expert
Community Expert
September 22, 2023

Then you can use something like this as the custom calculation script of the end date field (adjust the field names, options and date format as needed):

 

var startDate = this.getField("StartDate").valueAsString;
var term = this.getField("Term").valueAsString;
if (startDate=="") event.value = "";
else {
	var d = util.scand("mm/dd/yyyy", startDate);
	if (term=="28 Days") d.setDate(d.getDate()+28);
	else if (term=="60 Weeks") d.setDate(d.getDate()+(60*7));
	else if (term=="5 Years") d.setFullYear(d.getFullYear()+5);
	event.value = util.printd("mm/dd/yyyy", d);
}