Copy link to clipboard
Copied
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
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
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you!!!
Copy link to clipboard
Copied
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 = "";
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now