How to Combine List Box Selections and Custom Text in PDF Forms
Question details
The user needs to consolidate multiple list-box selections and manually entered text into a single PDF text field without losing the manual input upon recalculation.

- Product
- PDF Form Editor
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF form where a text field consolidates choices from a list box and allows custom manual additions.
- Observed behavior
- List-box selections populate correctly, but any manually entered custom text disappears from the text field as soon as it loses focus due to the script recalculating.
Ensure your PDF editor supports JavaScript for forms and that you have the exact property names of your list box and text field ready before implementing the calculation script.
Use an Independent Text Field for Custom Input
Prevent the calculation script from overwriting manual text by separating the custom input field from the final calculated output field.
Because calculated PDF fields automatically overwrite their contents upon recalculation (such as when the field loses focus), any manual typing directly into the calculated field will be instantly erased. The reliable approach is to capture the user's manual entry in an independent text field and merge it with the list box values using JavaScript.
Add a new text box to your PDF form and name it 'CustomText'. This is where users will manually type their extra information.
Select the main text field where you want the combined results to display, open its Properties, and navigate to the Calculate tab.
Select 'Custom calculation script' and paste the following code: var v = this.getField("Components").value; var custom = this.getField("CustomText").value; var parts = []; if (typeof v == "object") parts = v; else if (v) parts = [v]; if (custom) parts.push(custom); event.value = parts.join(", ");
Ensure you replace 'Components' with the exact name of your list box in the script, as JavaScript field names are case-sensitive.

Edit and Manage PDF Forms Easily with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to create interactive forms, add text fields, insert list boxes, and seamlessly manage document data across desktop and mobile devices.
- 1. Open your PDF: Launch WPS Office and open your PDF document containing the form layout.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive elements.
- 3. Add Text Fields and List Boxes: Select 'Text Field' or 'List Box' and click on your document to create your dynamic form areas.
- 4. Edit Properties: Double-click the added field or right-click and select 'Properties' to customize its name, appearance, and calculation actions.

Frequently Asked Questions
Why does my text disappear when a PDF field loses focus?
This occurs if the text field is configured to calculate data. Every time the form updates or the field loses focus, the calculation script triggers and automatically overwrites your manual input with the script's default result.
Can I combine multiple list box selections without using JavaScript?
Natively combining multiple selections into a distinct, dynamically updated text output requires a calculation script. However, you can allow users to visually select multiple items directly within the list box itself by enabling 'Multiple selection' in the list box properties.
Does this JavaScript work in all PDF readers?
The script relies on the standard JavaScript API for PDFs, which is supported by most major desktop PDF editors and readers. Note that some basic mobile PDF viewers or web browser viewers might lack full JavaScript support and may not execute the calculation.




