How to Show or Hide PDF Form Fields Based on Another Field Value
Question details
The user needs to configure a PDF form so that specific text fields automatically appear or disappear depending on the input value provided in a primary controlling field.
- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where sections must be dynamically revealed or hidden using conditional logic.
- Observed behavior
- By default, form fields remain statically visible or hidden. The goal is to make the dependent fields dynamically switch states when the controlling field's value changes.
Ensure your PDF editor supports JavaScript for interactive forms and identify the exact field names for both your controlling field and the dependent fields before adding the script.
Use a Custom JavaScript in the Validation Properties
Add a JavaScript snippet to the controlling field's validation or calculation properties to toggle the display status of dependent fields based on the user's input.
This method utilizes Acrobat JavaScript to check the value of a controlling field. When the user enters a specific value, the script updates the display property of designated fields to either visible or hidden.
Right-click the controlling text field in your PDF form editing mode and select Properties.
Click on the Validate tab (or Calculate tab) and select the option to run a custom validation script.
Input the logic to control dependent fields. For example, to show 'txt2' only when the value '1' is entered: this.getField("txt2").display = (event.value == "1") ? display.visible : display.hidden;
Add a new line for every dependent field that needs to be toggled, updating the target field name (e.g., "txt3", "txt4") and the expected condition value as necessary.

Easily Manage Interactive PDF Forms with WPS Office
WPS Office provides comprehensive PDF editing capabilities, allowing you to seamlessly create, manage, and fill interactive PDF forms without the need for expensive alternatives.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF application.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive form editing controls.
- 3. Manage Field Properties: Double-click any existing text field to review its properties, appearance, and configured interactive behaviors.

Frequently Asked Questions
Why is my PDF JavaScript not hiding the fields?
Check that the field names in your script perfectly match the actual field names in the PDF form, paying attention to exact spelling and case sensitivity. Also, ensure that JavaScript execution is enabled in your PDF viewer's security settings.
Can I use calculation scripts instead of validation scripts for form fields?
Yes, you can place the script in the Custom Calculation Script section. However, placing it in the Validate tab of the controlling field is often more efficient since the script will only trigger when that specific controlling field's value actually changes.
Will these conditional scripts work in all PDF viewers?
Advanced PDF editors and viewers fully support JavaScript for form logic. However, some basic or mobile PDF viewers, as well as native browser plugins, might not support interactive JavaScript execution, causing all fields to remain visible.




