How to Clear an Incorrect Radio Button in a PDF Form Using JavaScript
Question details
The user needs to set up a PDF form radio button group where selecting an incorrect answer displays an alert message and automatically clears the selection.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive quiz or assessment PDF form with multiple-choice radio buttons.
- Observed behavior
- The form must immediately notify the user of a wrong answer and reset the incorrectly selected radio button to an unselected state without affecting the correct answer.
Ensure your PDF editor supports JavaScript execution for form fields and that you are currently in the form editing or preparation mode.
Configure Mouse Up and Mouse Exit JavaScript Actions
Add a custom JavaScript snippet to display an alert when the button is clicked, and another script to clear the button when the mouse moves away.
By utilizing built-in JavaScript triggers in PDF forms, you can create interactive logic. The 'Mouse Up' event is perfect for triggering the alert because it fires immediately after the user completes a click. The 'Mouse Exit' event is then used to quietly reset the value to 'Off' as the user moves their cursor away.
Right-click the incorrect radio button in your PDF form editor and select Properties from the context menu.
Navigate to the Actions tab, select 'Mouse Up' as the trigger, and choose 'Run a JavaScript' from the action list. Add the following code: app.alert("This choice is incorrect.", 3);
Still in the Actions tab, add another action with 'Mouse Exit' as the trigger. Choose 'Run a JavaScript' and enter the code: event.target.value = "Off";
For the correct radio button in the group, open its properties and add a Mouse Up alert (e.g., app.alert("Correct!", 3);) but do not add the Mouse Exit clearing code.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF toolkit, allowing you to seamlessly create interactive forms, manage radio buttons, and edit form properties efficiently.
- 1. Open your PDF: Launch WPS Office and open your PDF document.
- 2. Enter Form mode: Navigate to the Form tab to access all interactive form controls, including radio buttons and text fields.
- 3. Edit properties: Double-click any form field to adjust its properties, appearance, and interactivity.

Frequently Asked Questions
Why isn't my JavaScript executing in the PDF viewer?
JavaScript might be disabled in your PDF viewer's security settings. Users must enable JavaScript execution in their PDF reader preferences for the interactive alerts and clearing scripts to function properly.
Can I group radio buttons so only one can be selected at a time?
Yes. To group radio buttons together, you must give them all the exact same field 'Name' in their properties. The 'Export Values' (or choices) must be different for each individual button in that group.
What does the '3' mean in the app.alert code?
The '3' indicates the icon type displayed in the alert dialog box. In Acrobat JavaScript, '3' typically displays an informational icon, while other numbers like '0' or '1' display error or warning icons respectively.
How do I clear a radio button without using JavaScript?
To clear a radio button natively without scripts, you can add a 'Reset a form' action to a separate push button on the page. In the configuration for that action, select only the specific radio button field you wish to be resettable.




