PDF Editing Issues

How to Show and Edit a PDF Text Field When a Checkbox is Selected

Elise WilliamsElise Williams Oct 28, 2026 868 views

Question details

The user wants to configure a PDF form checkbox to toggle the visibility and editability of a hidden, read-only text field using JavaScript.

How to Show and Edit a PDF Text Field When a Checkbox is Selected
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF form where text fields dynamically appear and become editable based on user checkbox selections.
Observed behavior
The user needs the correct JavaScript logic and display constants to conditionally reveal and unlock the target text field without relying on undefined constants.
Before you start

Ensure your PDF editing software supports interactive form creation and JavaScript editing, and verify the exact internal names of your checkbox and text fields.

Solution 1Recommended

Use JavaScript on the Checkbox Mouse Up Event

Add a custom Mouse Up script to your checkbox to control the target text field using standard PDF JavaScript display constants.

When creating interactive PDF forms, JavaScript allows you to dynamically change field properties. To ensure compatibility across different PDF viewers, you must use the standard constants `display.visible` and `display.hidden` rather than undefined variables.

1
Open form editing mode

Open your PDF file in an editor that supports form creation. Enter Form Editing mode and right-click on your Checkbox field to open its **Properties**.

2
Navigate to the Actions tab

In the Properties dialog, go to the **Actions** tab. Set the 'Select Trigger' dropdown to **Mouse Up**.

3
Add the JavaScript action

Set the 'Select Action' dropdown to **Run a JavaScript** and click the **Add** button to open the JavaScript Editor.

4
Input the script

Enter the following code: `if (event.target.value == "Yes") { var f = this.getField("amount_1"); f.readonly = false; f.display = display.visible; f.value = "default amount"; } else { var f = this.getField("amount_1"); f.readonly = true; f.display = display.hidden; f.value = ""; }`

5
Save and test

Click **OK** to close the JavaScript Editor, then click **Close** on the Properties dialog. Exit form editing mode to test clicking the checkbox.

Use JavaScript on the Checkbox Mouse Up Event
Verify Field Names: Be sure to replace 'amount_1' with the exact name of your hidden text field, and change 'Yes' to the actual export value defined in your checkbox's Options tab.
Manage PDF Forms with WPS Office

Easily Edit and Fill Interactive PDF Forms

WPS Office provides robust PDF tools to create, view, fill, and manage interactive PDF forms seamlessly. It's a comprehensive, lightweight solution for handling complex PDF tasks and daily document management.

  1. 1. Open WPS Office: Launch WPS Office and navigate to the **PDF** tab from the home screen.
  2. 2. Import your PDF form: Click **Open** to select and load your interactive PDF document into the workspace.
  3. 3. Interact with fields: Use the built-in form viewer to click checkboxes, fill in dynamically appearing text fields, and verify form logic.
  4. 4. Save and export: Click **Menu** > **Save As** to save your completed form data, or export it to share with others.
Fully compatible with standard interactive PDF forms and form fields.Lightweight software that loads large, complex PDF files instantly.Intuitive interface for both filling out forms and editing PDF text.Seamless cross-platform syncing across Windows, Mac, iOS, and Android.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my hidden PDF text field showing up when I click the checkbox?

This usually happens if the JavaScript references the wrong field name or uses an incorrect export value for the checkbox (e.g., your script checks for 'Yes' but the checkbox export value is set to 'On'). Double-check your exact field names and export values in the form properties.

What are the correct display constants for PDF JavaScript?

In PDF JavaScript, use `display.visible` to show a field, `display.hidden` to hide it, `display.noPrint` to show it on screen but hide it when printing, and `display.hiddenNoPrint` to hide it entirely. Using `0` or `1` can cause unexpected behavior in some viewers.

Can I toggle multiple text fields with one checkbox?

Yes. You can define multiple variables in your JavaScript `if` statement using `this.getField("field_name")` for each respective text field, and apply the `display.visible` or `display.hidden` properties to all of them within the same condition block.

How do I clear the text field value when hiding it?

Inside the `else` block of your JavaScript (which runs when the checkbox is unchecked), assign an empty string to the field's value property using `f.value = "";` just before setting its display property to hidden.