Skip to main content
Participant
May 8, 2025
Answered

Help with Javascript to calculate 120 consecutive dates

  • May 8, 2025
  • 1 reply
  • 590 views

Hi there, 

 

I need help creating a JavaScript calculation that will pull in 120 consecutive dates based on the initial date. The code I am using only pulls the next date. Any assistance would be greatly appreciated! 

 

var date = util.scand("mm/dd/yyyy", event.value);
if(event.value == "")
this.getField("Date1").value = "";
else {
date.setDate(date.getDate() +1);
this.getField("Date2").value = util.printd("mm/dd/yyyy", date);}

 

 

Thank you,

Angela

 

Correct answer PDF Automation Station

It works for me.  Did you copy and paste the code a custom validation script in Date1?  Did you also remove your calculation script?

1 reply

PDF Automation Station
Community Expert
Community Expert
May 8, 2025

Enter the following custom validation script in the Date1 field:

if(event.value)
{
var date = util.scand("mm/dd/yyyy", event.value);
for(var i=2;i<=120;i++)
{
date.setDate(date.getDate() +1);
this.getField("Date"+i).value = util.printd("mm/dd/yyyy", date);
}
}
Participant
May 8, 2025

Thank you for your help! The code entered date1 and date2 consecutively, but date3 through date120 populated the same date, 5/9/2025?

 

 

PDF Automation Station
Community Expert
Community Expert
May 9, 2025

It works for me.  Did you copy and paste the code a custom validation script in Date1?  Did you also remove your calculation script?