How to Auto-Populate Fields in an Acrobat PDF Form Using JavaScript
Question details
The user wants to automatically fill a specific field in a PDF form when a name is selected from another field, using JavaScript conditional logic.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that auto-fills related employee data based on a dropdown or text input selection.
- Observed behavior
- The user needs to implement logic so that selecting a name displays the correct abbreviation in a designated field, without overriding values incorrectly.
Ensure you have access to a PDF editor that supports form field properties and JavaScript execution, such as Adobe Acrobat Pro.
Implement JavaScript Arrays and Conditional Logic in the Form Field
Add a custom calculation script to the target field to check the selected name against predefined arrays and output the corresponding value.
By utilizing JavaScript arrays, you can group employees by their craft (e.g., Operators or Laborers). You can then use the indexOf method to check if the currently selected name exists within a specific array and populate the craft field accordingly.
Open your PDF form in your PDF editor, enter Form Editing mode, right-click the target field that should display the craft, and select Properties.
Navigate to the Calculate tab within the Properties dialog box and select the 'Custom calculation script' option.
Click the Edit button and input your array logic. First, define your array: var arr = ["JOHN DOE", "JANE SMITH"];
Add code to get the value from the Name field: var v = this.getField("Name").valueAsString;
Use an if-else statement to match the name and set the field value: if (arr.indexOf(v) !== -1) event.value = "OP"; else event.value = ""; Save the script and test the form.
Edit and Manage PDF Forms Easily with WPS Office
WPS Office includes a powerful PDF toolkit that allows you to view, fill, and manage interactive PDF forms efficiently. It serves as a highly compatible, lightweight alternative to heavy PDF editors.
- 1. Launch WPS Office: Open WPS Office and click on the PDF tab on the homepage to launch the PDF editor.
- 2. Open Your PDF File: Click the Open button or simply drag and drop your PDF form into the workspace.
- 3. Access Form Tools: Navigate to the Form tab on the top ribbon to access form filling and selection tools.
- 4. Fill the PDF Form: Click on the text fields, dropdowns, or checkboxes to input your data or modify the file.
- 5. Save the Completed Form: Click the Save icon in the top left corner to save your populated PDF form locally or to WPS Cloud.

Frequently Asked Questions
Why is my PDF form calculation not updating automatically?
In PDF forms, the calculation order and field properties matter. Ensure that the field triggering the change (e.g., the Name field dropdown) has the option 'Commit selected value immediately' enabled in its Options tab.
Can I pull data from an external database into a PDF form using JavaScript?
Standard PDF JavaScript executed in standalone readers generally cannot query external databases directly due to security restrictions. You must embed the data arrays within the document's custom calculation script.
How do I hide a form field entirely if no name is selected?
Instead of just setting the value to blank (event.value = ""), you can use this.getField("FieldName").display = display.hidden; to hide the field completely until the correct condition is met.




