Skip to main content
Participating Frequently
January 18, 2016
Question

How do I populate a date depending on what is selected in a drop down?

  • January 18, 2016
  • 1 reply
  • 1056 views

I have 1 field titled "Today" that populates the current date.  Then I have a drop-down field titled "Release Date" with the following selections: 14 Days, 180 Days, and Permanent.  I am trying to change the "Release Date" field into a calculated date using the "Today" field depending on what is selected in the drop-down list.  Example: If the "Today" field reads 01/18/2016 and the user selects "14 Days" from the drop-down list as the "Release Date" then I want the text to show as "02/01/2016", which is 14 days from today's date, instead of showing as "14 Days". What script should I use?

This topic has been closed for replies.

1 reply

Inspiring
January 18, 2016

If you want the date calculated, you will need to perform the calculation using custom JavaScript for the calculation.

Have you looked for scripts about adding # days to a given date?

The Acrobat JavaScript API Reference Manual has examples of date calculations. Use Date Objects

I would rather use JavaScript's getDate and setDate options for manipulating days.

hpdouet84Author
Participating Frequently
January 18, 2016

I'm new to this and have been reading so many discussions and verbiage on this that I am confusing myself more than anything.  This is the current custom calculation script I have:

(function () {

    // Get date from field
    var v = getField("Today").value;

    if (v) {

        // Convert string to date
        var d = util.scand('mm/dd/yyyy', v);

        // Add 14 days
        d.setDate(d.getDate() + 14);
        // Set value of this field to the new date
        event.value = util.printd("mm/dd/yyyy", d);

    } else {

        // Blank field if no date entered
        event.value = "";
    }
})();(function () {

    // Get date from field
    var v = getField("Today").value;

    if (v) {

        // Convert string to date
        var d = util.scand('mm/dd/yyyy', v);

        // Add 180 days
        d.setDate(d.getDate() + 180);
        // Set value of this field to the new date
        event.value = util.printd("mm/dd/yyyy", d);

    } else {

        // Blank field if no date entered
        event.value = "";
    }
})();

The issue I'm having is no matter which option is selected from the drop-down list, it still populates the date as Today + 180 days.

Inspiring
January 18, 2016

I see nothing that checks the dropdown selection for the number of days to use in the calculation.