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

Javascript to populate dropdown field to other fields with staggered dates

New Here ,
Dec 22, 2017 Dec 22, 2017

Hi,  I am trying to tweak a timesheet that I have added a dropdown box that has dates entered into the <Options>, <Item List> as "1/6/2018" and every 14 days til the end of the year. Where I am stuck is trying to get the javascript that will take the chosen 'Pay Period Ending' date and add to the 14th date field. Then I am trying to get all the other fields to start from this date -1 so that each date of the two-week period is shown. This way, the dropdown date will automatically update the pay period dates. I made some progress following these instructions https://answers.acrobatusers.com/How-autofill-date-field-based-field-selection-q286091.aspx and got the end date to reflect my date but could not get subsequent fields to -1 from the other for the staggered dates I need. The only other issue was date format in that drop downs are MM/DD/YYYY  but the 14 date fields for column hours tally are too small and need to be MM/DD. Thank you.

Timecard.PNG

TOPICS
Acrobat SDK and JavaScript
1.2K
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

correct answers 1 Correct answer

Community Expert , Dec 22, 2017 Dec 22, 2017

You can use something like this as the custom validation script of your drop-down (I can't make out the field names, so I'm using generic ones):

var d = util.scand("mm/dd/yyyy", event.value);

d.setDate(d.getDate()-1);

this.getField("Date1").value = util.printd("mm/dd", d);

d.setDate(d.getDate()-1);

this.getField("Date2").value = util.printd("mm/dd", d);

d.setDate(d.getDate()-1);

this.getField("Date3").value = util.printd("mm/dd", d);

// etc.

Translate
Community Expert ,
Dec 22, 2017 Dec 22, 2017

You can use something like this as the custom validation script of your drop-down (I can't make out the field names, so I'm using generic ones):

var d = util.scand("mm/dd/yyyy", event.value);

d.setDate(d.getDate()-1);

this.getField("Date1").value = util.printd("mm/dd", d);

d.setDate(d.getDate()-1);

this.getField("Date2").value = util.printd("mm/dd", d);

d.setDate(d.getDate()-1);

this.getField("Date3").value = util.printd("mm/dd", d);

// etc.

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 ,
Dec 22, 2017 Dec 22, 2017

Here's an article on this exact topic:

https://acrobatusers.com/tutorials/date_time_part2

It includes a time-sheet example

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 22, 2017 Dec 22, 2017
LATEST

Thanks Try67!! This worked like a champ. I didn't know that a validation field could cause other fields to be populated with specific data so this was enlightening. I entered your script into my dropdown validation script section after renaming my indiscernible field names to your "Date1", "Date2" and so forth. I did have to modify the initial -1 since the "Pay period end" date would be the same date as the chosen drop down date. Once I choose my dropdown option and click anywhere else, all the date range cells automatically update to the desired range. Awesome! Thank you very much.

Timecard1.PNG

Timecard2.PNG

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