PDF Editing Issues

How to Populate a Text Field with Checked Checkbox Values in PDF Forms

Phi Hung VoPhi Hung Vo Nov 24, 2026 870 views

Question details

The user wants to write a JavaScript function to automatically list the values of checked checkboxes inside a single multiline text box within a PDF form.

How to Populate a Text Field with Checked Checkbox Values in PDF Forms
Product
PDF
Device & OS
not provided
Scenario
Creating interactive PDF forms where a text field dynamically displays the specific options a user has selected via checkboxes.
Observed behavior
A multiline text field needs to be populated with the specific string values of checkboxes, separated by line breaks, only when those checkboxes are checked.
Before you start

Ensure you are using a PDF editor that supports form field creation and custom JavaScript calculations, and verify that your checkboxes have designated export values.

Solution 1Recommended

Configure a Custom JavaScript Calculation in the Text Field

Set the destination text field to accept multiple lines of text and apply a custom JavaScript calculation script to dynamically retrieve and display the checked values.

Interactive PDF forms can use JavaScript to pass data between fields. By assigning a custom calculation script to the target text field, the form will automatically check the status of your checkboxes every time the user interacts with them, updating the text box accordingly.

1
Enable the Multiline Property

Open your PDF form editor, right-click the target text field, and select 'Properties'. Navigate to the 'Options' tab and check the 'Multiline' box to ensure the field can display line breaks.

2
Access Calculation Settings

Switch to the 'Calculate' tab within the same text field properties window. Select the option labeled 'Custom calculation script'.

3
Enter the JavaScript Code

Click the 'Edit' button and paste the following script: `var c1 = this.getField('Checkbox 1').valueAsString; var c2 = this.getField('Checkbox 2').valueAsString; if(c1 !== 'Off' && c2 !== 'Off') { event.value = c1 + '\n' + c2; } else { event.value = ''; }`. Be sure to change 'Checkbox 1' and 'Checkbox 2' to the exact names of your actual checkbox fields.

4
Save and Test the Form

Click 'OK' to save the script and close the properties dialog. Exit form editing mode and test your document by clicking the checkboxes to verify that the text field populates with the correct values.

Configure a Custom JavaScript Calculation in the Text Field
Customizing the Logic: The provided script requires both checkboxes to be checked to display their values. If you want the text field to display values independently as each box is checked, you will need to separate the logic into distinct `if` statements that append the value to the text field if it is not equal to 'Off'.
WPS PDF Editor

Easily Manage Interactive PDF Forms with WPS PDF

WPS Office provides a comprehensive built-in PDF editor that allows you to view, fill, and manage interactive PDF forms without hassle. Whether you are dealing with checkboxes, text fields, or digital signatures, WPS PDF makes document handling seamless.

  1. 1. Open WPS Office: Launch WPS Office on your device and select the 'PDF' tab from the home screen.
  2. 2. Load Your PDF Form: Drag and drop your interactive PDF file into the workspace, or click 'Open' to browse your local files.
  3. 3. Interact with Form Fields: Simply click on the checkboxes or text fields within the document. WPS PDF automatically recognizes interactive elements, allowing you to fill out the form efficiently.
Fully compatible with standard PDF forms and interactive fields.Lightweight and fast PDF rendering for smooth reading and filling.Built-in tools for editing text, modifying images, and extracting form data.Cross-platform support for Windows, Mac, Linux, and mobile devices.
microsoft office alternative - wps office

Frequently Asked Questions

Why is the text field not displaying multiple lines even though I added the line break character?

The text field must have the 'Multiline' property explicitly enabled in its settings. Without this property checked, the newline character ('\n') will be ignored, and the text will be forced onto a single line.

How can I change the export value of a checkbox in a PDF form?

In your PDF editor's form preparation mode, right-click the checkbox and select 'Properties'. Go to the 'Options' tab, where you can define the 'Export Value' (e.g., 'Yes', 'Selected', or a specific category name). This is the exact string the JavaScript will retrieve when the box is checked.

Can I hide the text field if no checkboxes are selected?

Yes. You can add logic to your calculation script that checks if all checkbox values return 'Off'. If they do, you can set the text field's display property to hidden using `event.target.display = display.hidden;`, and revert it to `display.visible` when a box is checked.