How to Show or Hide a PDF Form Field Based on Two Other Fields
Question details
The user needs to conditionally display a specific PDF form field only when two distinct form fields contain exact numerical values, entirely bypassing the need for an intermediate calculation field.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an advanced, interactive PDF form where certain sections or fields are revealed dynamically based on multiple user inputs.
- Observed behavior
- The target field requires a logic rule to automatically switch its display status to visible or hidden by directly comparing the values of two other source fields.
Verify the exact names of the form fields you plan to reference, as PDF form scripting is strictly case-sensitive and relies on perfect name matching.
Use a Custom JavaScript Calculation
Apply a custom calculation script to the target field to evaluate the conditions of the other two fields and dynamically control its visibility.
By utilizing the built-in JavaScript capabilities of advanced PDF editors, you can pull the values of multiple fields simultaneously. Assigning this script to the target field ensures it continuously checks the source fields and updates its own display property automatically.
Open your PDF document in your PDF editor and activate the form creation or editing mode to reveal all interactive fields.
Right-click the field you want to hide or show (e.g., 'Reveal_A') and select 'Properties' from the context menu.
In the Properties dialog box, switch to the 'Calculate' tab and select the 'Custom calculation script' option.
Click the 'Edit' button and enter the following JavaScript code, adjusting the field names and values to match your form: var valA = this.getField('FieldA').value; var valB = this.getField('FieldB').value; if (valA == 75.5 && valB == 16.0) { event.target.display = display.visible; } else { event.target.display = display.hidden; }
Click 'OK' to save the script, close the Properties window, and exit form editing mode. Enter the exact target values into FieldA and FieldB to verify that Reveal_A becomes visible.

Create and Manage Dynamic PDF Forms with WPS Office
WPS Office provides robust PDF form creation and editing tools, allowing you to easily build interactive forms, insert text fields, checkboxes, and manage field properties seamlessly.
- 1. Open Your PDF: Launch WPS Office and open your PDF document using the PDF editor.
- 2. Enter Form Mode: Navigate to the 'Form' tab on the top ribbon to access interactive form tools.
- 3. Add Form Fields: Click on 'Text Field', 'Check Box', or 'Dropdown' to insert new fields into your document.
- 4. Adjust Properties: Double-click any inserted field to open the Properties menu, where you can define field names, appearance, and formats.

Frequently Asked Questions
Can I use text values instead of numbers for the field condition?
Yes, you can evaluate text strings by placing the expected values in quotation marks within the script, such as `if (valA == 'Yes' && valB == 'Approved')`.
Why is the target field not hiding when the conditions are false?
This usually happens due to mismatched field names in the script or because the source fields haven't triggered a recalculation. Double-check that capitalization matches exactly and try pressing 'Enter' or clicking outside the source fields to trigger the calculation.
Do I need to place the script in the source fields instead?
No, it is highly recommended to place the display logic in the Custom Calculation Script of the target field itself. This allows the target field to evaluate its own visibility status whenever the global PDF form calculation is triggered.




