Skip to main content
Participant
April 1, 2020
Question

Adding increasing dates to fillable PDF

  • April 1, 2020
  • 2 replies
  • 2666 views

Currently trying to make a timesheet template for work with a fillable pdf. I am trying to make it so when I input a date in a certain field, other fields (consecutive days of the week) will increase by one day. I can do it in excel (what the form was originally) but can't figure out how to do it in Acrobat. Thanks in advance for any help.

 

Example:

User inputs: 01-01-20

Next day (field): 01-02-20

This continues down the list of weekdays

2 replies

Thom Parker
Community Expert
Community Expert
April 1, 2020

I would suggest putting a script into the validate field of the initial date entry. This script will set the dates on all the consecutive date fields.

You'll find several posts here that provide solutions to this exact issue. 

But here's the basics for incrementing the day

 

var dateVal = util.scand("dd-mm-yy",event.valueAsString);

dateVal.setDate(dateVal.getDate()+1);

this.getField("NextDay").value = util.printd("dd-mm-yy",dateVal);

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
July 22, 2022

There's no such property as event.valueAsString, I think you meant event.value...

However, it might also be a good idea to check if it's not empty, as that would be interpreted as the current date when supplied to the scand method, which will produce incorrect results.

Thom Parker
Community Expert
Community Expert
July 22, 2022

Thanks Try, but a little late on the debug 😉

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
April 1, 2020
Participant
July 22, 2022

Link is no longer valid.

Nesa Nurani
Community Expert
Community Expert
July 22, 2022

Here is a sample I did for someone else, it's used in a date field as validation script where you pick date, it will populate 14 fields with consecutive days, fields are called Text1-Text14, you would need to adapt it to your requirements of course:

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