How to Make a Radio Button Required Only When a Text Field Is Filled in PDF Forms
Question details
The user needs to make a specific radio button group mandatory only when the corresponding text field in that row contains data.

- Product
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF form with repeating rows where radio button validation depends on whether a corresponding text input is provided.
- Observed behavior
- The radio buttons should dynamically toggle their 'required' status to true when the text field is not empty, and back to optional when the text field is cleared.
Ensure your PDF editor supports JavaScript for forms and that each text field and radio button group has a unique, identifiable name assigned to it.
Use a Custom JavaScript for Form Fields
Apply a custom calculation or validation script to the text field to automatically monitor its value and adjust the radio button's required property.
In PDF forms, field dependencies are managed using JavaScript. By adding a simple script to the text field, the document can check if the field is empty and immediately enforce validation rules on the associated radio buttons.
Enter the form editing mode in your PDF editor. Right-click the target text field (e.g., the fruit field) and select Properties from the context menu.
Go to the 'Calculate' or 'Validate' tab within the Properties window. Select the option to run a 'Custom calculation script' or 'Custom validation script'.
Click the Edit button and input your JavaScript. Use a script similar to: if (event.value !== '') { this.getField('RadioGroup1').required = true; } else { this.getField('RadioGroup1').required = false; }.
Repeat this process for every row in your form. Ensure you update the field names in the script (e.g., 'RadioGroup2', 'RadioGroup3') to match the corresponding row accurately.
Close the Properties window, exit form editing mode, and test the form. Type a value into the text field, click outside of it to trigger the script, and verify that the radio button becomes mandatory.

Manage and Fill Interactive PDF Forms with WPS Office
WPS PDF provides a lightweight and powerful suite of tools for viewing, managing, and filling out complex, interactive PDF forms. Enjoy a seamless experience handling scripted fields and validations.
- 1. Install WPS Office: Download and install the free WPS Office suite on your computer.
- 2. Open Your PDF Form: Launch WPS PDF and open the interactive PDF form containing the scripted fields.
- 3. Fill the Data: Navigate through the form. As you fill out the text fields, any correctly scripted conditional logic will trigger automatically.
- 4. Save and Export: Once the form is filled and validated, click Save or use the Export option to share your completed document.

Frequently Asked Questions
Why isn't the radio button becoming required immediately after I type?
Form scripts typically trigger only after you exit the field. Try clicking outside the text field or pressing the 'Enter' or 'Tab' key to commit the data and trigger the script.
Can I use this same method to make checkboxes required?
Yes. The JavaScript logic is identical. You simply replace the radio button group's field name in the script with the exact field name of your checkbox.
Do I have to write the script for every single text field individually?
For straightforward implementations, yes, each text field needs its own script targeting the specific radio button in its row. Advanced users can write a document-level script using a naming convention to handle this dynamically, but applying it row by row is safest for beginners.




