How to Toggle PDF Form Fields Visible and Hidden with a Button
Question details
The user wants to configure a button within a PDF document to dynamically toggle the visibility of specific form fields.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where certain input fields appear or disappear based on the user clicking a dedicated button.
- Observed behavior
- Requires a JavaScript solution to check the target field's current display state and switch it between visible and hidden on alternating clicks.
Ensure you are using a PDF editor that supports interactive form creation and JavaScript execution, and verify the exact name of the form field you intend to hide.
Use a JavaScript Action to Toggle Field Visibility
Assign a custom JavaScript code to the button's action properties to switch the target field's display state upon each click.
This method uses a conditional JavaScript statement to check if the target field is currently visible. If it is visible, the script hides it; if it is hidden, the script makes it visible again.
Open your PDF document and enter Form Editing mode. Ensure the field you want to toggle (e.g., a text box named 'TargetField') is already created.
Create a Button form field on your document. Right-click the newly created button and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. Choose 'Mouse Up' as the Select Trigger, choose 'Run a JavaScript' from the Select Action dropdown, and click the 'Add' button.
In the JavaScript Editor window, enter the following code: var f = this.getField("TargetField"); f.display = (f.display == display.visible) ? display.hidden : display.visible;
Click 'OK' to close the editor, then close the Properties dialog. Switch your PDF editor to Preview mode (or open it in a standard PDF reader) to test the toggle button.

Create and Edit Interactive PDF Forms with WPS Office
WPS PDF provides comprehensive form creation tools, allowing you to seamlessly add text fields, buttons, and checkboxes. It is the perfect tool for building interactive documents efficiently.
- 1. Open WPS Office PDF: Launch WPS Office and open your PDF document using the dedicated PDF module.
- 2. Navigate to the Form Tab: Click on the 'Form' tab located on the top ribbon to access the suite of interactive field elements.
- 3. Insert Form Controls: Select 'Push Button', 'Text Field', or 'Check Box', then click and drag on the document to place the element.
- 4. Customize Field Properties: Double-click the inserted form element to modify its name, appearance, and interactive actions.

Frequently Asked Questions
Why is my JavaScript button not hiding the PDF form field?
Ensure that JavaScript execution is enabled in your PDF viewer's preferences. Additionally, verify that the field name referenced in the `getField` function exactly matches the target field's name, including spaces and capitalization.
Can I toggle multiple PDF fields with a single button click?
Yes. You can control multiple fields by expanding the JavaScript code. Simply duplicate the `var f = this.getField("FieldName");` and the corresponding `f.display` line for each field you wish to toggle within the same script window.
Will these interactive PDF buttons work on mobile devices?
It depends on the mobile PDF reader being used. Basic built-in mobile readers often do not support JavaScript execution. For interactive forms to function correctly, users should open the PDF in advanced applications like WPS Office or Adobe Acrobat for mobile.




