Skip to main content
Known Participant
May 31, 2025
Answered

Merge multiple text boxes into one text box

  • May 31, 2025
  • 1 reply
  • 812 views

I have five text boxed named Name1, Name2, Name3, Name4 and Name5.  When I enter names into each of these text boxes, I would like to populate another text box, named All Names, with these names.  If I filled in Allan in Name1, Bob in Name2, Charlie in Name3, Donald in Name4 and Edward in Name5, I would like All Names to look like this:

 

Allan

Bob

Charlie

Donald

Edward

 

I have tried using this custom calculation script in All Names, but the names all populate on the same line in All Names, not on different lines:

 

event.value = this.getField("Name1").value  +  this.getField("Name2").value +  this.getField("Name3").value +  this.getField("Name4").value +  this.getField("Name5").value;

 

I think I need to insert code for a carriage return after each name.

Correct answer Thom Parker

Yep, opps, typo.

 

var aNames = [];
var cName;
for(var i=1;i<=5;i++){
 cName = this.getField("Name" + i).value;
  if(!/^\s*$/.test(cName))
     aNames.push(cName);
}

event.value = aNames.join("\n");

 

 

1 reply

Thom Parker
Community Expert
Community Expert
May 31, 2025

try this script:

var aNames = [];
var cName;
for(var i=1;i<=5;i++){
 cName = this.getField("Name" + 1).value;
  if(!/^\s*$/.test(cName))
     aNames.push(cName);
}

event.value = aNames.join("\n");

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
May 31, 2025

When I type the names into the text fields, I get this result in the All Names text field:

 

Allan

Allan

Allan

Allan

Allan

Nesa Nurani
Community Expert
Community Expert
May 31, 2025

There is a small error in the script in this part:

("Name" + 1)

replace 1 with i, like this:

("Name" + i)