Fix Acrobat JavaScript for Copying PDF Form Field Values
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.

- 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 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.
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.
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'.
Right-click the button that triggers the copy action, select 'Properties', and go to the 'Actions' tab.
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.
Set the target value by adding 'targetField.value = sourceValue;' to your script. Save the changes and test the button in standard viewing mode.

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. Open WPS PDF: Launch WPS Office and click on the 'PDF' tab to open the built-in PDF editor.
- 2. Load Your PDF Form: Open your interactive PDF document containing the form fields you want to manage.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access form creation and editing tools.
- 4. Edit Field Properties: Double-click any form field to view and adjust its properties, names, and actions directly, then save your document.

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.




