Use Acrobat JavaScript to Calculate a Field from Radio Button Values
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.

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

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.

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.




