How to Show Optional Form Paragraphs Based on Checkbox Selections in PDF
Question details
The user wants to create a fillable PDF form that dynamically displays specific paragraphs based on checkbox selections, ensuring that unselected text is hidden and does not leave blank spaces when printed.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating advanced fillable PDF forms that require conditional text display based on user choices.
- Observed behavior
- Hidden text fields typically leave blank gaps in the layout. The goal is to exclude unselected text from the print view, allowing the remaining content to flow upward without empty spaces.
Ensure your PDF editing software supports form field creation and custom JavaScript calculations. Prepare the exact text paragraphs you want to display for each checkbox option.
Use a Custom Calculation Script in a Multiline Text Field
Combine your optional texts into a single multiline text box that dynamically populates based on checkbox states, preventing blank gaps in the document layout.
Instead of showing and hiding individual text fields, which leaves blank spaces on the page, the most effective method is to use a single multiline text field. A JavaScript calculation script checks which boxes are ticked and compiles the corresponding text into that single field. This causes the text to flow naturally without gaps.
Add your checkbox form fields to the PDF document (e.g., Checkbox1, Checkbox2, Checkbox3) and note their exact field names.
Create a new text field where the conditional paragraphs will appear. Right-click the field, go to Properties, navigate to the Options tab, and check the 'Multi-line' box.
Go to the Calculate tab in the text field's properties, select 'Custom calculation script', and click the Edit button.
Input a script that builds an array based on checkbox values. For example: var texts = []; if (this.getField("Checkbox1").valueAsString != "Off") texts.push("Text of the first paragraph..."); if (this.getField("Checkbox2").valueAsString != "Off") texts.push("Text of the second paragraph..."); if (this.getField("Checkbox3").valueAsString != "Off") texts.push("Text of the third paragraph..."); event.value = texts.join("\n\n");
Switch to the hand tool or preview mode. Select and deselect the checkboxes to verify that the text field updates dynamically and formats the paragraphs with line breaks.

Create and Edit Professional PDF Forms with WPS Office
WPS PDF, built into WPS Office, provides a comprehensive set of tools for viewing, creating, and editing fillable forms, offering a seamless experience for managing dynamic document requirements.
- 1. Open WPS Office: Launch the application and open your PDF document using the integrated WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal form creation and editing tools.
- 3. Insert Form Controls: Use the interactive buttons to add checkboxes, text fields, and dropdowns directly to your document.
- 4. Configure Properties: Double-click any form field to customize its appearance, export values, and calculation logic.

Frequently Asked Questions
Why is there a blank space when I use show/hide actions on individual text fields?
If you assign show/hide scripts to separate text fields, hiding them leaves their designated physical space empty on the page. Combining them into one multiline text field ensures the text flows upward automatically.
How do I make the generated text field read-only?
Open the Properties of your multiline text field, navigate to the General tab, and check the 'Read Only' box. This ensures the text only changes via the checkbox selections and prevents users from manually typing in the box.
Can I format different paragraphs with bold or italic text in the same multiline field?
Standard PDF multiline text fields apply a single font style to all contents. To use rich text formatting (like bolding specific words), you must enable 'Allow Rich Text Formatting' in the field options and use Rich Text JavaScript methods, which requires more advanced scripting.
What happens if I rename my checkboxes after writing the script?
If you rename the checkbox fields in your PDF, you must also manually update the corresponding field names in your custom calculation script (e.g., this.getField("NewCheckboxName")). Otherwise, the script will fail to retrieve the values.




