PDF Editing Issues

Use Acrobat JavaScript to Calculate a Field from Radio Button Values

Steve KSteve K Nov 19, 2026 869 views

Question details

Display 1 in a PDF form field when either Always or Mostly Yes is selected, and leave the field blank for the other choices.

Calculate a Field from Radio Button Values in Acrobat
Product
Adobe Acrobat Pro
Device & OS
not provided
Scenario
A PDF questionnaire uses a radio-button group with four response options and a separate field for the calculated result.
Observed behavior
The result field should show 1 for Always or Mostly Yes and remain blank for Hardly Ever or Never.
Before you start

Open the questionnaire in Adobe Acrobat Pro and identify the radio-button group name and the field that will display the result. Check each button's export value; the script compares those values, not necessarily the visible labels.

Solution 1Recommended

Add a custom calculation script to the result field

Use this method to calculate the result automatically from the radio-button group's selected export value.

1
Open the form editor

In Acrobat, open the PDF and select All tools > Prepare a form. Select the radio-button group and open its Properties to confirm its name, such as Q1.

2
Check the export values

Open Properties for each radio button and check the Options tab. Confirm that the export values for the two relevant choices are exactly Always and Mostly Yes, or note their actual values for use in the script.

3
Add the calculation

Open Properties for the result text field, select the Calculate tab, and choose Custom calculation script > Edit. Enter: var v = this.getField("Q1").valueAsString; event.value = (v == "Always" || v == "Mostly Yes") ? 1 : "";

4
Match the field and values

In the script editor, replace Q1 with your radio-button group name if different. Replace Always and Mostly Yes if the actual export values differ, then confirm the script and close Properties.

5
Test the form

Select Preview in Prepare a form and click each radio button. Verify that Always and Mostly Yes display 1, while Hardly Ever and Never leave the result blank. Save the PDF.

Add a custom calculation script to the result field
Use exact export values: The comparisons are case-sensitive. A button's displayed label can differ from the export value used by the script.
Free Microsoft Office alternative

Work with PDF questionnaires and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. It can help with everyday document editing and migration, but it is not a replacement for configuring this Acrobat-specific JavaScript calculation.

Open PDF questionnaires alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface for everyday document tasksMove between common Office file formats and PDFs
microsoft office alternative - wps office

Frequently Asked Questions

Where do I enter the JavaScript in Acrobat?

In Prepare a form, open the result text field's Properties, select Calculate, and choose Custom calculation script > Edit. Enter the script in that editor.

What if the radio-button labels differ from their export values?

Use the export values in the script. Check each button's Properties > Options tab and replace the strings Always and Mostly Yes with the exact values used in the form.

Why does the result stay blank after I select Always?

Check that the name in this.getField("Q1") matches the radio-button group name and that the button's export value exactly matches the string in the script. Both spelling and capitalization matter.

Can I add this calculation in Acrobat Reader?

Acrobat Reader is intended for viewing and filling forms. Use Acrobat Pro's Prepare a form tools to add or edit the custom calculation script.