PDF Editing Issues

How to Clear an Incorrect Radio Button in a PDF Form Using JavaScript

Chanuka GeekiyanageChanuka Geekiyanage Nov 5, 2026 869 views

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.

How to Clear an Incorrect Radio Button in a PDF Form Using JavaScript
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.
Before you start

Ensure your PDF editor supports JavaScript execution for form fields and that you are currently in the form editing or preparation mode.

Solution 1Recommended

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.

1
Open form field properties

Right-click the incorrect radio button in your PDF form editor and select Properties from the context menu.

2
Add Mouse Up alert

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);

3
Add Mouse Exit reset code

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";

4
Configure the correct answer

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.

Repeat for all options: You must repeat these configuration steps for each radio button in the group, ensuring only the incorrect ones contain the Mouse Exit clearing code.
Powerful PDF Form Editor

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. 1. Open your PDF: Launch WPS Office and open your PDF document.
  2. 2. Enter Form mode: Navigate to the Form tab to access all interactive form controls, including radio buttons and text fields.
  3. 3. Edit properties: Double-click any form field to adjust its properties, appearance, and interactivity.
Easily insert and manage radio buttons, text fields, and checkboxes.Highly compatible with standard PDF forms and Adobe Acrobat formats.Lightweight software with an intuitive, user-friendly interface for seamless editing.
microsoft office alternative - wps office

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.