How to Validate PDF Text Fields Based on Radio Buttons via Acrobat JavaScript
Question details
The user wants to require specific numeric increments in a text field depending on which radio button (Small, Medium, Large) is selected in a PDF form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where text field inputs must be conditionally validated based on the user's prior radio button selection.
- Observed behavior
- By default, PDF text fields do not enforce conditional validation increments based on the state of other form elements without applying a custom JavaScript logic.
Ensure you have access to a robust PDF editor equipped with advanced form editing and JavaScript execution capabilities, such as Adobe Acrobat Pro.
Use a Custom Validation Script on the Text Field
Assign a shared field name to your radio buttons and apply a custom JavaScript validation to the corresponding text field to enforce the required numerical increments.
To achieve conditional validation, you must ensure all related radio buttons act as a single group. The text field will then check the active value of this group before accepting input.
Open your PDF form editor. Give all three radio buttons the exact same field name, such as "Size". Assign a unique Export Value to each button: "Small", "Medium", and "Large".
Right-click the target text field and open its Properties. Navigate to the Format tab, select "Number" from the built-in format options, and set the decimal places. This prevents users from entering alphabetical characters.
In the text field's Properties, go to the Validate tab. Choose 'Run custom validation script' and enter the following JavaScript code: var v = Number(event.value); var size = this.getField("Size").valueAsString; if (size == "Large" && v % 50 != 0) { app.alert("Enter a value that is a multiple of 50.", 1); }
Because the text field validation only triggers when the text field itself is edited, you must also add a small script to the radio buttons' 'Mouse Up' action to re-evaluate the text field if the user changes their size selection after entering a number.

Fill and Manage Interactive PDF Forms with WPS Office
WPS Office provides excellent PDF reading and editing capabilities, allowing you to seamlessly fill out, manage, and interact with complex PDF forms, including those configured with standard embedded validations.
- 1. Download and install: Download WPS Office for free from the official website and complete the installation process.
- 2. Open the PDF document: Launch WPS Office, click on the PDF tab, and open the interactive PDF form you need to fill out.
- 3. Interact with form fields: Click on the configured radio buttons and text fields to input your data. WPS PDF supports seamless interaction with pre-configured standard form validations.
- 4. Save or export: Once the form fields are validated and filled, easily save the document or export it directly as a finalized PDF to share with others.

Frequently Asked Questions
Why isn't the validation triggering when I change the radio button after entering text?
The text field's custom validation script only executes when the user inputs or modifies data inside that specific text field. If the user changes the radio button later, the text field does not automatically re-validate. To fix this, you must add an action script to the radio button group that forces the text field to re-check its value upon a selection change.
How do I restrict the text field so users can only type numbers?
In your PDF form editor, open the text field Properties and navigate to the Format tab. Select 'Number' from the category list. This natively restricts user input to numeric characters and helps prevent JavaScript calculation errors.
Do JavaScript form validations work in all PDF viewers?
No, not all third-party or browser-based PDF viewers support embedded JavaScript execution. For forms utilizing custom validation scripts, users should be advised to open the document in robust PDF software like Adobe Acrobat or compatible desktop PDF editors.




