Populate an Acrobat Form Field from a JavaScript Dialog
Question details
Place the first and last names entered in an Acrobat JavaScript dialog into a PDF form’s Name text field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form uses a custom JavaScript dialog to collect a first name and a last name.
- Observed behavior
- The combined name should appear in the Name text field instead of being printed to the JavaScript console.
Make sure the PDF has a text field named exactly Name and an existing JavaScript dialog with input item IDs fnam and lnam. You’ll need access to edit the Acrobat JavaScript that opens the dialog.
Write the dialog results to the Acrobat Name field
Update the existing dialog’s commit function to join the two inputs and assign the result to the form field.
The dialog’s commit function is called when the dialog is accepted. Keep a reference to the PDF document because this inside the dialog object may not refer to the document.
In Acrobat, open the PDF and locate the script that launches the dialog. For a button action, open Prepare a form, right-click the button, choose Properties > Actions, and edit its Run a JavaScript action.
In the document or button action script, before defining the dialog object, add: var pdfDoc = this;
In the existing dialog object’s commit function, replace the console.println line with: pdfDoc.getField("Name").value = results["fnam"] + " " + results["lnam"]; If results has not already been defined in that function, first add: var results = dialog.store();
Save the script, exit form editing, and open the dialog using its existing trigger. Enter both names and accept the dialog; check that the Name field displays them separated by a space.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for viewing PDFs and working with Office documents. It can help you move between common file formats, but the Acrobat-specific JavaScript dialog must be edited and tested in Acrobat.

Frequently Asked Questions
Why use pdfDoc instead of this inside the commit function?
Inside the dialog object, this may refer to the dialog rather than the PDF document. Capture the document with var pdfDoc = this before defining the dialog, then use pdfDoc.getField("Name") in commit.
How do I find the correct form field name?
In Acrobat, open Prepare a form and inspect the text field’s properties. Use the exact field name shown there in getField(), including capitalization.
What does dialog.store() do?
In the commit function, dialog.store() retrieves the dialog item values. Assign its result to a variable, such as var results = dialog.store(), before reading results["fnam"] and results["lnam"].
Why doesn’t the Name field update after I accept the dialog?
Check that the dialog’s commit function runs, the field is named Name, and the input IDs are fnam and lnam. In Acrobat, open the JavaScript console to look for script errors, and confirm that JavaScript is enabled.




