Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with Javascript to calculate 120 consecutive dates

New Here ,
May 08, 2025 May 08, 2025

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

 

TOPICS
How to , JavaScript , PDF forms
154
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
May 08, 2025 May 08, 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);
}
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2025 May 08, 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?

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2025 May 08, 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);
}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 08, 2025 May 08, 2025

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

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2025 May 08, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2025 May 09, 2025
LATEST

Aha! I thought I deleted the custom validation script, but alas, I did not. 

 

 

Thanks for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines