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

Possible to auto-calculate date 2 weeks past user-entered date in form?

New Here ,
Jun 27, 2016 Jun 27, 2016

Hello! I'm trying to create a form that auto populates a few dates based on a user-entered value. For example, if a user enters a due date of 7/1/16, I would like another field to auto-populate with 7/15/16 (2 weeks from the previously entered date). Is this possible? I've been searching for scripts but no luck so far.

Thanks!

Melissa

TOPICS
Acrobat SDK and JavaScript , Windows
915
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 , Jun 27, 2016 Jun 27, 2016

Sure, it's possible. Let's say the name of the date field entered by the user is Date1. You can use this script as the custom calculation script of the other field.

var dateString = this.getField("Date1").valueAsString;

if (dateString=="") event.value = "";

else {

    var d = util.scand("m/dd/yy", dateString);

    d.setDate(d.getDate()+14);

    event.value = util.printd("m/dd/yy", d);
}

For a tool that allows you to set up such calculations easily, see: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation

...
Translate
Community Expert ,
Jun 27, 2016 Jun 27, 2016

Sure, it's possible. Let's say the name of the date field entered by the user is Date1. You can use this script as the custom calculation script of the other field.

var dateString = this.getField("Date1").valueAsString;

if (dateString=="") event.value = "";

else {

    var d = util.scand("m/dd/yy", dateString);

    d.setDate(d.getDate()+14);

    event.value = util.printd("m/dd/yy", d);
}

For a tool that allows you to set up such calculations easily, see: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation

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 ,
Jun 27, 2016 Jun 27, 2016

Thank you!!!

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 ,
Jun 27, 2016 Jun 27, 2016
LATEST

Date calculations in Acrobat's JavaScript implementation are done the same way as in every other JavaScript system: The "Date" object is part of the JavaScript core language. You can find out more about the Date object here: Date - JavaScript | MDN

You can find tutorials about how to use the Date object in Acrobat here: https://acrobatusers.com/tutorials/date_time_part1

The key is to use the getDate()/setDate()  methods: Let's assume you get a date from field "Date1", and set the new date in "Date2", you can use something like this as the custom calculation script of the Date2 field:

var dateStr = this.getField("Date1").value;

if (dateStr != "") {

  var theDate = util.scand("mm/dd/yyyy", dateStr);

  theDate.setDate(theDate.getDate() + 14);

  event.value = util.printd("mm/dd/yyyy", theDate);

}

else {

  event.value = "";

}

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