Skip to main content
Participant
August 10, 2025
Question

Form field copy without naming the fields the same

  • August 10, 2025
  • 1 reply
  • 216 views

Hi!

 

I think I originally posted this to the wrong community. I need help to create a JavaScript code. I think. lol. I need to copy the info from each field in line 1 to the next line. Using the same field name doesn't work bc I don't use each line every time I complete a form. 

1 reply

Thom Parker
Community Expert
Community Expert
August 10, 2025

What triggers the copy?  

There are many different ways this can be done.  The most effective is to use group naming. The base field name is the same on each line, but the name is prefixed with text that differentiates the lines. 

For example "Line1.FromMM", "Line1.FromDD", etc.  

 

Then code on a button on line #2 could acquire all fields on line #1 with one command. And copy it with another

Like this:

 

// Get all fields on line 1
 var aLine1Fields = this.getField("Line1").getArray();
// This loop copies data form line 1 to line2
aLine1Fields.forEach(function(a){this.getField(a.name.replace("Line1","Line2")).value = a.value;});



A little more code and this could be abstracted into a folder level function that works for all lines.   

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often