Skip to main content
Participant
January 9, 2019
Answered

Repopulate PDF Form Fields Down to New Section of Form with Button

  • January 9, 2019
  • 1 reply
  • 481 views

At work, for each project I submit, I use a pdf form that has the information from the previous two editions of that project, as well as the current. We manually copy each field down each year (CurrentPages gets copied to PrevPages, etc.). I was hoping I could use javascript and a button to make this automatic. Can anybody help? Some of these fields are text fields, some are drop down lists, etc. Each field that needs populated will already need filled and will need cleared and/or overridden.

This topic has been closed for replies.
Correct answer Thom Parker

Yes, copying data between field is quite simple, and the type of field doesn't matter.

For your issue, the important thing is that the field names have a predicable and sequential naming convention. Then you can write code that takes advantage of the naming to find and transfer the field data

For example, you could name the fields in the first groupt "1.Text1" "1.Text2" etc. and the fields in the second group "2.Text1" "2.text2" and so on with as many groups as necessary.

This groups the fields using a number. Fields in each group have the same name, but with a different group prefix.

This code will transfer the data no matter the field type of number of fields in each group

for(var i=2;i>1;i--)

{

    aFldList = this.getField(i).getArray();

    for(var n=0;n<aFldList.length;n++)

      aFldList.value =  this.getField(aFldList.name.replace(/^\d/,i-1)).value;

}

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 9, 2019

Yes, copying data between field is quite simple, and the type of field doesn't matter.

For your issue, the important thing is that the field names have a predicable and sequential naming convention. Then you can write code that takes advantage of the naming to find and transfer the field data

For example, you could name the fields in the first groupt "1.Text1" "1.Text2" etc. and the fields in the second group "2.Text1" "2.text2" and so on with as many groups as necessary.

This groups the fields using a number. Fields in each group have the same name, but with a different group prefix.

This code will transfer the data no matter the field type of number of fields in each group

for(var i=2;i>1;i--)

{

    aFldList = this.getField(i).getArray();

    for(var n=0;n<aFldList.length;n++)

      aFldList.value =  this.getField(aFldList.name.replace(/^\d/,i-1)).value;

}

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