How to Populate Fields Based on a Dropdown Selection in PDF with JavaScript
Question details
The user needs a script to automatically fill rate, billing, and package fields in a PDF form when a specific value is selected from a Units dropdown menu.

- Product
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where certain dependent text fields auto-populate based on another dropdown field's selection.
- Observed behavior
- The current script is assigned to a Mouse Up action and fails to execute correctly when the dropdown selection changes, leaving the dependent fields un-updated.
Ensure you have form editing permissions for the PDF document and access to the JavaScript debugger console to troubleshoot potential script errors.
Use a Custom Calculation Script for the Destination Field
Move the JavaScript from the source dropdown's Mouse Up action to the destination field's Custom Calculation Script. This ensures the value updates dynamically whenever the dropdown changes.
A Mouse Up script only triggers when a user clicks and releases the mouse on that exact field, which is ineffective for dependent dropdown calculations. By using a Custom Calculation Script on the destination field, the PDF reader automatically recalculates the value anytime any field in the document is modified.
Additionally, if your output includes currency symbols (e.g., "$75"), the destination field cannot be formatted strictly as a Number, as the text string will cause a formatting conflict.
Enter form editing mode in your PDF editor. Right-click the destination field (e.g., the Rate or Billing field) that you want to populate, and select 'Properties'.
Navigate to the 'Calculate' tab and select the 'Custom calculation script' option. Click 'Edit' and paste your conditional logic. For example: var units = this.getField("Units").value; if(units == "50") event.value = "$75"; else if(units == "100") event.value = "$119"; else event.value = "";
Switch to the 'Format' tab in the same Properties window. If your script outputs a string containing a currency symbol, ensure the format category is set to 'None' or 'Text' rather than 'Number'.
Exit form editing mode and select different values in your 'Units' dropdown menu to verify that the destination field updates correctly.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides an intuitive, comprehensive PDF editor that allows you to effortlessly design interactive forms, insert dropdown menus, and configure text fields without dealing with complex coding environments.
- 1. Open your PDF: Launch WPS Office and open the PDF document you want to convert into an interactive form.
- 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon to reveal various interactive form controls.
- 3. Add Interactive Fields: Click on 'Text Field', 'Combo Box', or other elements, and drag on the page to place them. Double-click the placed fields to customize their properties and behavior.
- 4. Save and Distribute: Once your form fields are set up, save the document. The interactive elements will be usable in any standard PDF reader.

Frequently Asked Questions
Why does my JavaScript not trigger on a Mouse Up action?
A Mouse Up action is only triggered when the user physically clicks and releases the mouse on the specific field the script is attached to. For populating dependent fields based on a dropdown, a Custom Calculation Script is required so the logic automatically runs whenever the form's data state changes.
How do I troubleshoot PDF JavaScript errors?
You can troubleshoot script errors by opening the JavaScript debugger console. In many standard PDF editors, including Acrobat, you can access this console by pressing Ctrl+J. The console logs syntax errors and helps identify why a script failed to execute.
Why am I getting a formatting error when auto-filling a currency value?
If you assign a string containing a currency symbol (like "$75") to a field that is strictly formatted to accept only 'Numbers', the PDF reader will throw a format error. To fix this, change the destination field's formatting category to 'None' or 'Text', or use a custom format script to append the currency symbol to a pure number.




