How to Make a PDF Form Field Required Based on Radio Button Selection
Question details
The user needs a dependent text field in a PDF form to become required when a 'Yes' radio button is selected, and optional or read-only when 'No' is selected.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where text field requirements change dynamically based on the user's radio button choices.
- Observed behavior
- The required status of the dependent field does not update automatically when the user switches between the Yes and No radio button selections.
Ensure you are using a PDF editor that supports form field property management and custom JavaScript execution, such as WPS Office or Adobe Acrobat.
Use a JavaScript Action on the Mouse Up Event
Apply a custom JavaScript script to trigger when the radio button is clicked to dynamically update the dependent field's required property.
By attaching a script to the 'Mouse Up' trigger, the PDF software executes the code the moment the user makes a selection. You must apply this script to both the 'Yes' and 'No' radio button instances to ensure the dependent field's status updates correctly when the user changes their mind.
Open your PDF form in editing mode. Right-click the 'Yes' radio button and select 'Properties' from the context menu.
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 the 'Add' button.
In the JavaScript Editor window, paste the following code: var Q = this.getField('RadioGroupName'); var A = this.getField('DependentFieldName'); if (Q.value === 'Yes') { A.required = true; } if (Q.value === 'No') { A.required = false; }
Replace 'RadioGroupName' and 'DependentFieldName' with your exact field names. Save the script, close the properties window, and repeat these exact steps for the 'No' radio button.

Create and Manage PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily add, modify, and manage interactive form fields, helping you create professional, fillable documents with ease.
- 1. Open Your PDF: Download and launch WPS Office, then open the PDF document you want to turn into an interactive form.
- 2. Access Form Tools: Go to the 'Form' tab located in the top navigation ribbon to access the form building tools.
- 3. Insert Form Fields: Select 'Radio Button' or 'Text Field' from the toolbar and click on the document to place the interactive elements.
- 4. Configure Properties: Double-click the inserted fields to configure their names, set them as required, and adjust other specific properties.

Frequently Asked Questions
Why does my JavaScript only work on the first radio button click?
This usually happens if the script is only applied to one of the radio buttons. Ensure that the 'Mouse Up' JavaScript action is added to the properties of both the 'Yes' and 'No' radio button options within the same group.
Can I make the field read-only instead of just optional?
Yes, you can modify the JavaScript to change the readonly property. Add `A.readonly = true;` when the value is 'No' and `A.readonly = false;` when the value is 'Yes'.
What trigger should I use for form field scripts?
The 'Mouse Up' trigger is generally recommended for buttons and radio buttons. It fires exactly when the user completes the click action (releases the mouse button), ensuring the value has been correctly updated before the script runs.
Do I need advanced programming skills to create dynamic PDF forms?
No, most interactive PDF form logic requires only basic JavaScript, such as simple if/else statements to check field values and set basic properties like required, readonly, or hidden.




