How to Calculate a Due Date from a Submission Date in PDF Forms
Question details
The user needs to create an automated calculation in a PDF form that adds the number of days selected in an Invoice Terms drop-down to a Submission Date field to populate a Due Date field.

- Product
- PDF Form Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF invoice or form where the payment deadline dynamically updates based on the selected terms and the date submitted.
- Observed behavior
- The user requires a custom calculation script to fetch values from a date field and a drop-down field, perform a date addition, and return the formatted result into a third field.
Ensure your PDF editor supports JavaScript for custom field calculations. Additionally, verify that your 'Invoice Terms' drop-down options are assigned numerical export values (e.g., '0' for Due on receipt, '30' for Net 30).
Apply a Custom Calculation JavaScript to the Due Date Field
Use a custom JavaScript to read the submission date, parse it, add the specified number of days from the drop-down, and output the new date to the Due Date field.
PDF forms use standard JavaScript to handle complex field interactions. The util.scand and util.printd functions are specifically used to parse string inputs into date objects and format them back into strings.
Open your PDF in form editing mode. Right-click the 'Due Date' text field and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties window. Choose the 'Custom calculation script' option and click the 'Edit' button.
Paste the following script into the editor: var terms = Number(this.getField('Invoice Terms Dropdown').valueAsString); var submission = this.getField('Submission Date').value; if (submission == '') { event.value = ''; } else { var date = util.scand('mm-dd-yyyy', submission); date.setDate(date.getDate() + terms); event.value = util.printd('mm-dd-yyyy', date); }
Open the Properties for your 'Invoice Terms Dropdown' field. Under the 'Options' tab, ensure each item has an 'Export Value' that contains only the numeric number of days (e.g., '30').

Create, Edit, and Manage PDF Forms with WPS PDF
WPS Office provides a comprehensive and easy-to-use PDF editing suite. You can effortlessly fill out interactive forms, edit text, insert dates, and manage your documents securely.
- 1. Download and Install: Download WPS Office for free and launch the application on your device.
- 2. Open the PDF File: Click on the 'PDF' tab and open your interactive invoice or form document.
- 3. Fill the Form Fields: Click directly on the interactive fields, such as drop-downs and text boxes, to input your data and dates.
- 4. Save and Export: Once your form is completely filled out, save the document or export it directly as a flat PDF to send to your clients securely.

Frequently Asked Questions
Why is my calculated date returning an error or showing blank?
This usually happens if the date format in the script (e.g., 'mm-dd-yyyy') does not perfectly match the format of the date entered in the Submission Date field, or if the field names have a typo.
Can I use a text field instead of a drop-down for the Invoice Terms?
Yes. The same script will work with a text field instead of a drop-down, provided the user types a valid numerical value representing the number of days into the field.
How do I exclude weekends from the due date calculation?
The standard setDate() function adds continuous calendar days. Excluding weekends requires a more advanced JavaScript loop that checks the day of the week using date.getDay() and skips over Saturdays (6) and Sundays (0).
How do I correctly set up the drop-down list to output numbers?
In the drop-down field properties under the 'Options' tab, type your descriptive text (like 'Net 30') into the 'Item Name' box, and type the corresponding number ('30') into the 'Export Value' box. Then click 'Add'.




