How to Require a Radio Button Selection Before Leaving a PDF Form
Question details
The user wants to display a pop-up enforcing a radio button selection before someone exits a PDF form.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms and ensuring required fields are completed by the respondent.
- Observed behavior
- PDF readers lack built-in settings to reliably block closing the document if a radio button is unselected.
Understand that standard PDF readers cannot reliably intercept application close events. Focus on enforcing validation during the form submission process instead.
Use JavaScript to Validate Radio Buttons on Form Submit
Since blocking document closure isn't feasible, the best approach is attaching a validation script to the submit button.
PDF viewers prioritize user control, meaning you cannot stop a user from clicking the 'X' to close the software. However, you can prevent them from successfully submitting the form if the required radio button is not selected by using custom JavaScript on the submit action.
Open your PDF editor and navigate to the Form editing tools.
Right-click your 'Submit' button and select 'Properties'.
Navigate to the 'Actions' tab, choose 'Run a JavaScript' from the Select Action dropdown, and click 'Add'.
Input a script that checks the value of your radio button group. If it is empty, display a pop-up alert (e.g., app.alert('Please select an option');) and abort the submission.

Set the Radio Button Field as 'Required'
Use native form properties to visually highlight and enforce the field completion before saving or submitting.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily add, edit, and configure form fields, including required radio buttons and text boxes.
- 1. Open your PDF: Launch WPS Office and open your PDF document.
- 2. Enter Form Mode: Navigate to the 'Form' tab to access interactive field tools.
- 3. Add Radio Buttons: Click 'Radio Button' and place it on your document. Double-click to access its properties and mark it as required.
- 4. Save and Export: Save your newly interactive PDF, ready to be distributed to users.

Frequently Asked Questions
Can I force a user to save a PDF before closing?
No, standard PDF readers do not allow scripts to intercept or block the application's close command to force a save. Users always retain the ability to exit the application.
What happens if a user submits a form without filling required fields?
If the fields are set to 'Required' in the properties, the PDF reader will usually display a warning prompt and prevent the submission action until the fields are completed.
Does WPS Office support JavaScript in PDF forms?
Yes, WPS Office supports adding custom JavaScript to form fields and buttons for advanced validation and interactive behaviors.




