How to Show a PDF Form Field Based on Other Field Values
Question details
The user needs to display a conditional PDF form field or specific text based on the values entered into other fields.

- Product
- Device & OS
- not provided
- Scenario
- Setting up advanced PDF form calculations where a field's visibility or value dynamically changes depending on user input in referenced fields.
- Observed behavior
- The visibility script fails to show the field properly due to incorrect JavaScript targeting or mismatched data types between numeric values and text strings.
Ensure your PDF editor supports custom JavaScript for interactive form fields, and note down the exact names of the fields you intend to reference.
Configure Conditional Field Visibility Using JavaScript
Fix the JavaScript visibility script by using the correct display target syntax and ensuring exact value type matches.
When scripting conditional visibility in PDF forms, the script must accurately target the display property of the specific field. A common mistake is using `event.display` instead of `event.target.display`. Additionally, JavaScript strictly compares data types, so a numeric `0` will not match a formatted text string like `"0.00"`.
Right-click the PDF form field you want to conditionally display and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties window and select the 'Custom calculation script' option.
In your JavaScript code, use `event.target.display = display.visible;` (or `display.hidden`) to ensure the visibility state is applied to the intended form field.
Use the syntax `this.getField("FieldName").value` to pull data from other fields. Ensure your condition logic accounts for exact data type matches, specifically checking if the returned value is a numeric zero (0) or a formatted text string ("0.00").

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily design interactive forms, edit field properties, and ensure your documents look professional.
- 1. Open your PDF: Launch WPS Office and open the PDF document you want to edit.
- 2. Navigate to Form Tools: Click on the 'Form' tab located in the top navigation ribbon.
- 3. Insert Form Fields: Select the desired form control, such as a 'Text Field', and click on the page to place it.
- 4. Adjust Properties: Double-click the inserted field to open the Properties panel, where you can customize its appearance and behavior.

Frequently Asked Questions
Why does my JavaScript fail to hide the PDF form field?
This usually happens when the script incorrectly targets the display object. Ensure you are using `event.target.display = display.hidden` rather than `event.display = display.hidden`.
How do I reference another field's value in a PDF script?
You can retrieve the value of another field by using the `this.getField("ExactFieldName").value` method in your custom JavaScript.
Can I set a PDF field to be hidden by default without coding?
Yes. Open the field's Properties, go to the 'General' tab, and change the 'Form Field' property dropdown from 'Visible' to 'Hidden'.




