How to Display PDF Form Results Based on Another Field Using Acrobat JavaScript
Question details
The user needs to use a custom JavaScript calculation in a PDF to conditionally display a specific value based on the input of another field.

- Product
- Adobe Acrobat PDF Form
- Device & OS
- not provided
- Scenario
- Creating dynamic and interactive PDF forms with conditional logic.
- Observed behavior
- The target field needs to automatically update its value to match either Conclusion1 or Conclusion2 based on the input provided in the Gender field.
Ensure you are in the PDF form editing mode and have accurately named your reference fields (e.g., 'Gender', 'Conclusion1', and 'Conclusion2') before applying the custom calculation script. Field names in JavaScript are strictly case-sensitive.
Use a Custom Calculation Script in Adobe Acrobat
Apply a JavaScript snippet to the target field's calculation properties to dynamically fetch and display values based on the referenced field.
To achieve this, you need to use Acrobat's built-in JavaScript engine. By reading the string value of the condition field (like 'Gender'), you can assign the corresponding text from other fields to the current field using 'event.value'.
Launch Adobe Acrobat, open your PDF document, and click on 'Tools' > 'Prepare Form' to enter form editing mode.
Right-click the target field (e.g., the Percentage or Results field) where you want the conditional result to appear, and select 'Properties' from the context menu.
In the Properties dialog box, navigate to the 'Calculate' tab and select the radio button for 'Custom calculation script'.
Click the 'Edit' button and paste the following code: var gender = this.getField("Gender").valueAsString; if (gender == "1") { event.value = this.getField("Conclusion1").valueAsString; } else if (gender == "2") { event.value = this.getField("Conclusion2").valueAsString; } else { event.value = ""; }
Click 'OK' to close the JavaScript editor, then click 'Close' on the Properties dialog. Click 'Preview' at the top right to test your form by entering "1" or "2" into the Gender field.

Manage and Edit PDF Forms Easily with WPS Office
WPS Office provides a robust PDF toolkit that allows you to view, fill, edit, and manage interactive PDF forms effortlessly without needing expensive software.
- 1. Install WPS Office: Download and install the free version of WPS Office from the official website.
- 2. Open Your PDF: Launch WPS PDF and open the interactive PDF form document you need to fill out or manage.
- 3. Fill and Edit: Use the intuitive 'Form' tools provided to quickly fill out text fields, check boxes, or apply your digital signature.
- 4. Save and Export: Save your completed form locally or share it directly while maintaining full layout and data integrity.

Frequently Asked Questions
Why isn't my PDF JavaScript calculation working?
This usually happens if the field names in your script do not exactly match the actual field names in your PDF form. Field names are case-sensitive. Check your 'Gender', 'Conclusion1', and 'Conclusion2' field properties to ensure they match exactly.
Can I hide the conclusion fields so users only see the final result?
Yes. You can set the 'Conclusion1' and 'Conclusion2' fields to 'Hidden' in their Properties under the General tab. The JavaScript will still be able to run silently, read their values, and display the result in your visible target field.
How do I trigger the calculation script to run?
Calculation scripts automatically trigger whenever any field value in the PDF changes. To test it, simply enter a value like '1' or '2' into the referenced field and hit Enter, or click anywhere outside the field. The result will display immediately.




