Other PDF Issues

How to Return Two Values from an Acrobat JavaScript Function

Maira MehtabMaira Mehtab Nov 5, 2026 870 views

Question details

The user needs to retrieve multiple calculated outputs (a primary and a secondary response) from a single Acrobat JavaScript dialog function.

How to Return Two Values from an Acrobat JavaScript Function
Product
Adobe Acrobat PDF
Device & OS
not provided
Scenario
Writing or troubleshooting custom JavaScript for interactive PDF dialogs or forms where multiple variables must be extracted from a function.
Observed behavior
The current Acrobat dialog function only returns the first calculated variable, failing to pass the secondary response back to the caller.
Before you start

Ensure you have the Acrobat JavaScript debugging console enabled in your PDF editor's preferences so you can easily test and verify the function's output.

Solution 1Recommended

Use an Array to Return Multiple Values

Since JavaScript functions can only execute one return statement, packaging multiple variables into an array is the standard method to return them together.

In JavaScript, a function stops executing immediately after it reaches a return statement. If you attempt to use two separate return statements, the second one will be completely ignored. By grouping both of your response variables inside a single array object, you can pass all necessary data back to the calling code simultaneously.

1
Modify the return statement

In your Acrobat JavaScript dialog function, replace the single variable return with an array bracket notation. For example, instead of "return resp;", write "return [resp, otherResp];".

2
Store the function output

In the part of your script that triggers the function, assign the function call to a variable so it catches the array, such as "var result = yourDialogFunction();".

3
Access the returned values by index

Retrieve the individual values from the array using their numerical index. Use "result[0]" to access the primary response (resp) and "result[1]" to access the secondary response (otherResp).

Use an Array to Return Multiple Values
Alternative Method: Using an Object: If you want your code to be more readable, you can return a JavaScript object instead, like "return { primary: resp, secondary: otherResp };". You would then access them using "result.primary" and "result.secondary".
Advanced PDF Form Editing with WPS Office

Easily Manage Interactive PDF Forms Using WPS Office

WPS Office provides a highly capable PDF editing suite that allows you to manage interactive forms, edit text, and customize document structures smoothly. It offers full compatibility with standard PDF formats as a lightweight, user-friendly alternative.

  1. 1. Open your PDF in WPS Office: Launch WPS Office, click on the 'Open' button, and select the PDF file containing the interactive form elements you wish to manage.
  2. 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon. This section displays all interactive fields, buttons, and form-related properties.
  3. 3. Customize Form Field Properties: Right-click on any form field and select 'Properties'. Here you can adjust appearance, format validations, and custom calculation behaviors.
Create, edit, and fill interactive PDF forms effortlessly.Fully compatible with standard Adobe PDF formats and form fields.Lightweight application design ensures fast loading speeds.Comprehensive built-in tools for document annotation and conversion.
microsoft office alternative - wps office

Frequently Asked Questions

Can I return more than two values from an Acrobat JavaScript function?

Yes, you can add as many elements as you need to the returned array. For example, you can write 'return [val1, val2, val3];' and access them sequentially using their indices (0, 1, and 2).

Why does my Acrobat function ignore the second return statement?

JavaScript execution stops immediately after the first 'return' statement is processed. Any subsequent 'return' commands within the same block are considered unreachable code and are ignored, which is why grouping values into a single array or object is necessary.

Is it better to return an array or an object in PDF JavaScript?

Arrays are simpler and faster for returning a short, ordered list of variables. Objects are better if you are returning multiple values and want to reference them by specific property names (like 'result.primary') to make your script easier to read and maintain.