PDF Editing Issues

Populate an Acrobat Form Field from a JavaScript Dialog

Khadija KhanKhadija Khan Nov 19, 2026 869 views

Question details

Place the first and last names entered in an Acrobat JavaScript dialog into a PDF form’s Name text field.

Populate an Acrobat Form Field from a JavaScript Dialog
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the existing script

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.

2
Capture the document reference

In the document or button action script, before defining the dialog object, add: var pdfDoc = this;

3
Update the commit function

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();

4
Test the form

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.

Write the dialog results to the Acrobat Name field
Check field and item names: The field name Name and dialog item IDs fnam and lnam must match the names in your PDF and dialog script exactly.
Free Microsoft Office alternative

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.

Open and review PDF forms in WPS OfficeWork with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface to ease migration from Microsoft OfficeAccess document and PDF tools in one lightweight suite
microsoft office alternative - wps office

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.