How to Combine Dropdown Values in PDF Forms Using JavaScript
Question details
The user needs to concatenate the export values from two PDF form dropdown fields and use an if-then script to evaluate the combined text and populate a description field.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Automating data entry in interactive PDF forms by evaluating combined selections from multiple dropdown menus.
- Observed behavior
- The existing JavaScript calculation script fails to run due to syntax errors, specifically missing parentheses around the if-condition and mistakenly using an assignment operator (=) instead of a strict equality operator (===).
Ensure your PDF form contains the necessary dropdown fields, and that you have assigned accurate export values to the items in each dropdown menu before applying calculation scripts.
Use Concatenation and Strict Equality in a Custom Calculation Script
Directly combine the dropdown values into a single variable using JavaScript concatenation, then use strict equality (===) to evaluate the condition and set the description field value.
When writing scripts for PDF forms, using correct JavaScript syntax is crucial. To combine text strings from multiple fields, use the + operator. For condition checks in an if-statement, always enclose the condition in parentheses and use === to verify strict equality instead of the assignment operator =.
Open your PDF form in editing mode, right-click the target description text field where the output should appear, and select 'Properties'.
Navigate to the 'Calculate' tab within the Properties window. Select the 'Custom calculation script' option and click 'Edit'.
Define a variable to combine the export values from your dropdown fields using .valueAsString. For example: var code = this.getField("SectionRow1.0").valueAsString + this.getField("ITEMRow1").valueAsString;
Add an if-else statement to evaluate the concatenated string. Ensure you use parentheses and the === operator. For example: if (code === "DSL") { event.value = "FREE Standard Listing - Name, Address, City & Phone"; } else { event.value = "Not Valid"; }
Click 'OK' to save the custom script, close the Properties window, and test your dropdown menus to ensure the description field updates correctly based on your selections.

Create and Edit Interactive PDF Forms with WPS PDF
WPS Office includes a comprehensive PDF editor that allows you to easily design interactive forms, insert dropdown menus, text fields, and apply custom calculation logic to streamline your document workflows.
- 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 on the top ribbon to reveal all interactive form field options.
- 3. Insert Form Fields: Click on 'Combo Box' or 'Text Field' to draw your desired dropdowns and description boxes on the page.
- 4. Configure Properties: Double-click the inserted fields to set up their names, export values, and any necessary calculation logic, then save your interactive PDF.

Frequently Asked Questions
Why is my PDF JavaScript if-then statement throwing a syntax error?
Syntax errors in if-then statements are usually caused by missing parentheses around the condition or using a single equals sign (=) instead of double (==) or triple (===) equals. A single equals sign assigns a value, whereas double/triple equals are used to compare values.
What is the difference between .value and .valueAsString in PDF JavaScript?
The .value property returns the exact data type of the field, which could be a number or a string. The .valueAsString property forces the returned value to be treated purely as text. Using .valueAsString is highly recommended when combining field values to prevent unexpected mathematical additions.
How do I retrieve the selected export value of a dropdown list in a PDF form?
You can retrieve the selected export value of a dropdown by using the getField method in your script. For example, this.getField("YourDropdownName").value will return the export value associated with the user's current selection.




