PDF Editing Issues

Fix Acrobat JavaScript for Copying PDF Form Field Values

Muhammad TalhaMuhammad Talha Nov 5, 2026 869 views

Question details

A custom button script intended to copy values from one PDF form field to another is failing, often due to how the software handles duplicated or hierarchical field names.

How to Fix Acrobat JavaScript That Copies PDF Form Field Values
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A user is creating an interactive PDF form and trying to use JavaScript on a button to copy user-inputted values between different form fields.
Observed behavior
The script fails to execute or copy values properly because the software automatically alters field names into hierarchical structures (e.g., Site_Name.Site_Name) when fields are copied or duplicated.
Before you start

Before modifying your PDF JavaScript code, open the 'Prepare Form' tool to review the exact, current names of all your form fields, as duplicated fields may have automatically changed names.

Solution 1Recommended

Update JavaScript with Exact Field Names and Proper Value Assignments

Fix duplicate or hierarchical names in your form and use the getField() method correctly to retrieve and assign values as strings.

When fields are duplicated, PDF editors often assign hierarchical names to prevent them from acting as identical linked fields. To make your copy script work, you need to reference these exact names and explicitly extract their string values.

1
Identify Exact Field Names

Open your PDF document in your PDF editor and navigate to the 'Prepare Form' panel to check the exact names of your source and destination fields. Note any hierarchical names like 'Address_1.Address_1'.

2
Edit Button Action

Right-click the button that triggers the copy action, select 'Properties', and go to the 'Actions' tab.

3
Modify JavaScript Code

Select 'Run a JavaScript' and click 'Edit'. Use 'this.getField("Source_Field_Name").valueAsString' to retrieve the source value, and 'this.getField("Destination_Field_Name")' to define the target field.

4
Assign the Value

Set the target value by adding 'targetField.value = sourceValue;' to your script. Save the changes and test the button in standard viewing mode.

Update JavaScript with Exact Field Names and Proper Value Assignments
JavaScript Code Example: Example implementation: var tTown1 = this.getField("Town").valueAsString; var tTown2 = this.getField("C_Town"); tTown2.value = tTown1;
Seamless PDF Form Editing

Edit and Fill PDF Forms with WPS Office

If you are experiencing issues with complex PDF scripts, try WPS Office. WPS provides an intuitive PDF editor that makes creating, filling, and managing interactive PDF forms simple without relying on complex scripting troubleshooting.

  1. 1. Open WPS PDF: Launch WPS Office and click on the 'PDF' tab to open the built-in PDF editor.
  2. 2. Load Your PDF Form: Open your interactive PDF document containing the form fields you want to manage.
  3. 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access form creation and editing tools.
  4. 4. Edit Field Properties: Double-click any form field to view and adjust its properties, names, and actions directly, then save your document.
Easily create and edit interactive PDF formsHigh compatibility with standard PDF formats and Adobe Acrobat filesLightweight all-in-one office suite for Word, Excel, PowerPoint, and PDFUser-friendly interface for managing form fields and properties
QA img-9

Frequently Asked Questions

Why do my PDF form fields automatically change names when copied?

When you duplicate a form field, the software often creates a hierarchical name (like Field.0, Field.1, or FieldName.FieldName) to prevent the new field from automatically mirroring the exact same inputted value as the original field.

What is the difference between value and valueAsString in PDF JavaScript?

The 'value' property retrieves the data in its native format (which could be a number or an object), while 'valueAsString' strictly retrieves the field's content as plain text, which prevents formatting errors when copying text like addresses or names.

Can I test my PDF JavaScript form buttons without Adobe Acrobat?

Yes, standard PDF form JavaScripts will execute in most modern PDF readers, including WPS PDF and standard web browsers, provided that JavaScript execution is enabled in the software's security settings.