How to Make a PDF Form Field Required When a Checkbox is Checked
Question details
Dynamically change a PDF text field to be required or optional based on the selection state of a specific checkbox.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where certain data entry is only mandatory if the user actively selects a related checkbox option.
- Observed behavior
- The goal is to automatically update the target text field's required property in both states (checked and unchecked) when the user interacts with the checkbox.
Ensure you are using a PDF editor that supports form authoring and JavaScript actions, and carefully note the exact field names for both your checkbox and text field before applying any scripts.
Use a Mouse-Up Action Script on the Checkbox
Add a custom JavaScript action to the checkbox that triggers when clicked, immediately updating the required state of the target text field.
This method is highly recommended because the 'Mouse Up' trigger fires exactly when the user completes their click on the checkbox, ensuring the form logic responds instantly without needing to click away.
Enter the form editing mode of your PDF editor. Right-click the checkbox you want to use as the trigger and select 'Properties'.
Navigate to the 'Actions' tab. Select 'Mouse Up' from the Select Trigger dropdown menu, and choose 'Run a JavaScript' from the Select Action dropdown. Click 'Add'.
In the JavaScript Editor window, paste the following code: var target = this.getField("myTextField"); var checkbox = event.target; target.required = checkbox.value != "Off"; Make sure to replace "myTextField" with the actual name of your target text field.
Click 'OK' to close the editor, then close the Properties dialog. Exit form editing mode and test the checkbox to verify the text field becomes required when checked.
Apply a Custom Calculation Script to the Target Text Field
Alternatively, place the script on the text field itself so it continuously evaluates the state of the checkbox to determine its own required status.
Dynamically Hide or Show the Text Field
Instead of only making the field required, you can choose to hide the text field completely until the checkbox is checked, keeping the form interface cleaner.
Create Interactive PDF Forms with WPS Office
Easily design, edit, and embed interactive elements like checkboxes, text fields, and custom scripts into your PDF documents using WPS PDF's intuitive form tools.
- 1. Open your PDF Document: Launch WPS Office and open your PDF file using the WPS PDF editor.
- 2. Navigate to Form Tools: Click on the 'Form' tab in the top ribbon to access the interactive form controls.
- 3. Add Interactive Elements: Select the 'Check Box' or 'Text Field' tools to place new interactive elements onto your document page.
- 4. Configure Properties: Double-click the placed element to open its Properties dialog, rename the fields, and inject necessary JavaScript actions.

Frequently Asked Questions
Why doesn't the text field become required immediately after I check the box?
This usually happens if the script is tied to the wrong trigger, such as 'On Blur' (when the field loses focus). Ensure your JavaScript is set to the 'Mouse Up' trigger in the checkbox properties so it executes the moment you release the click.
How do I find the exact name of my PDF form fields?
While in form editing mode, the field names are typically displayed inside or directly next to the field boundaries. You can also right-click the field, select Properties, and look at the 'Name' text box under the General tab.
Can I make multiple text fields required based on just one checkbox?
Yes. In your JavaScript code, you can define additional variables for the other target fields (e.g., target2, target3) and apply the same `required = checkbox.value != "Off";` logic to each one in the same script.




