How to Return Two Values from an Acrobat JavaScript Function
Question details
The user needs to retrieve multiple calculated outputs (a primary and a secondary response) from a single Acrobat JavaScript dialog 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.
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.
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.
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];".
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();".
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).

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. 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. 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. Customize Form Field Properties: Right-click on any form field and select 'Properties'. Here you can adjust appearance, format validations, and custom calculation behaviors.

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.




