How to Populate Consecutive Month Fields from a PDF Drop-Down List
Question details
The user needs to create an automated calculation in a PDF form that fills two consecutive text fields with the next two months depending on the initial month chosen from a drop-down menu.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Designing dynamic PDF forms that require automated field population based on a user's selection.
- Observed behavior
- Requires a script or method to dynamically output the correct subsequent months and wrap correctly back to January at the end of the year.
Ensure that your PDF form editing software supports custom JavaScript calculations and that you have already created the source drop-down list and target text fields.
Use a Custom JavaScript Calculation
Apply a short JavaScript snippet to the target text fields that locates the selected month in an array and assigns the next values.
This method uses a standard array of twelve months. By extracting the selected index from your drop-down list, you can add 1 or 2 to the index to find the consecutive months. Using the modulo operator (% 12) ensures that December wraps seamlessly back to January.
Open your PDF in form editing mode. Ensure your drop-down list is named exactly 'StartMonth' and create two empty text fields for the subsequent months.
Right-click the first text field and select 'Properties'. Go to the 'Calculate' tab, select 'Custom calculation script', and click the 'Edit' button.
Enter the following code: var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; var d = this.getField('StartMonth').valueAsString; var idx = months.indexOf(d); if (idx !== -1) { event.value = months[(idx + 1) % 12]; } else { event.value = ''; }
Open the properties for your second text field, navigate to the calculation script editor, and use the exact same code, but change '(idx + 1)' to '(idx + 2)' to calculate the month after next.
Easily Create and Manage Interactive PDF Forms in WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to create drop-down lists, add text fields, and design professional interactive forms quickly and efficiently.
- 1. Open your PDF document: Launch WPS Office and open the PDF file you wish to convert into an interactive form.
- 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal the interactive form controls.
- 3. Insert Form Controls: Select 'Combo Box' to insert a drop-down list or 'Text Field' to add areas for user input and calculations.
- 4. Configure Properties: Double-click the inserted fields to access their properties and configure appearance, options, and behaviors.

Frequently Asked Questions
How do I make the month calculation wrap back to January at the end of the year?
You can handle year-end wrapping by using the modulo operator (% 12) in your JavaScript. For example, if December is index 11, calculating (11 + 1) % 12 gives a result of 0, which correctly maps to January in a zero-indexed array.
Why are my PDF text fields not updating when I change the drop-down selection?
This usually happens because the form isn't instructed to update right away. Open the properties of your drop-down list, navigate to the 'Options' tab, and ensure 'Commit selected value immediately' is checked.
Can I use numerical month values instead of text names?
Yes. You can modify the array in your script to contain numbers instead of names (e.g., ['01', '02', '03' ... '12']). The same index-based calculation logic will still apply.




