How to Populate a PDF Text Field from Two Drop-Down Lists
Question details
The user needs a method to dynamically fill a target text field in a PDF form based on the selected values from either of two different drop-down lists.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where text fields calculate and display data derived from multiple drop-down menus.
- Observed behavior
- The user requires a calculation script that defines precedence between two drop-down lists and successfully updates a text field using the selected export value or displayed text.
Ensure that your PDF form already contains the target text field and the two drop-down list fields, and note their exact field names to reference them correctly in your script.
Use Custom JavaScript Calculation for the Text Field
Apply a custom JavaScript calculation script to the target text field to evaluate both drop-down lists and display the correct value based on your desired precedence.
In interactive PDF forms, a text field can use custom JavaScript to pull and calculate data from other form fields. By assigning a script to the target text field's Calculate property, you can dictate exactly which drop-down value to display.
When defining precedence, you can use conditional (if-else) statements to check if the first drop-down is empty before falling back to the second drop-down's value.
Enter your PDF editor's form preparation mode. Right-click the target text field that you want to populate and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to view calculation options for this specific field.
Select the 'Custom calculation script' radio button and click 'Edit'. Enter a script to evaluate the fields. For example: var a = this.getField("dropdownA").valueAsString; var b = this.getField("dropdownB").valueAsString; event.value = (a !== "") ? a : b;
Click 'OK' to save the script, then close the Properties window. Exit form editing mode and select values in your drop-down lists to verify that the text field updates automatically according to your script's logic.

Create and Manage Interactive PDF Forms with WPS Office
WPS PDF provides robust, intuitive tools for creating professional and interactive PDF forms. Easily insert text fields, manage drop-down lists, and customize properties to collect data seamlessly.
- 1. Open WPS PDF: Launch WPS Office and open your existing PDF document or create a new one.
- 2. Access Form Tools: Navigate to the 'Form' tab located on the top ribbon menu to view interactive form components.
- 3. Insert Drop-Downs and Text Fields: Click on 'Drop-Down' or 'Text Field' and drag on your document page to place the elements.
- 4. Configure Properties: Double-click any inserted field to open the Properties menu, where you can configure names, export values, and formatting.

Frequently Asked Questions
What is the difference between a drop-down's display text and its export value?
The display text is the visible label a user sees and selects in the drop-down menu. The export value is the hidden, underlying data assigned to that option, which is used for scripts, calculations, and data processing.
Can I combine the values of both drop-down lists into a single text field?
Yes, you can concatenate the values in your JavaScript calculation. For example, using event.value = this.getField("list1").valueAsString + " " + this.getField("list2").valueAsString; will display both selections separated by a space.
Why is my text field not updating when I change the drop-down selection?
This usually happens if the calculation order is incorrect, if the field names in your script do not exactly match the actual form field names, or if a syntax error exists in your JavaScript. Check the console for script errors and verify field names.




