Skip to main content
Known Participant
July 6, 2016
Answered

how to trim and concatenate two text fields in a form

  • July 6, 2016
  • 1 reply
  • 1587 views

Hi folks,

Newbie here... have two fields in a form:  FirstName   and   LastName.    Want to have these show up later as:  LastName, FirstName.

For example:    "Rick"   "Stockstill"   would show up later as:   "Stockstill, Rick"    with a comma separating names and trailing blanks removed.

This is a piece of cake in Excel, but have not figured out how to do same with Acrobat.    My first try at a script looks like this:

(Recipient.rawValue=trim(LastName.rawValue)+", "+FirstName.rawValue);

The   "Recipient"  field is a standard text field that I'm trying to populate using the  "Calculate"  property.  The good news is that I get no error message, but the bad news is that the  Recipient  field does not get populated.

Any and all assistance greatly appreciated.

Till later,
Rick Stockstill
North East Independent School District
San Antonio, TX
210-407-0317
rstock@neisd.net

This topic has been closed for replies.
Correct answer try67

OK, in that case you can use this code as the custom calculation script of the Recipient field:

event.value = trim(this.getField("LastName").valueAsString) + ", " + trim(this.getField("FirstName").valueAsString);

function trim(s) {

    return s.replace(/^\s+/,"").replace(/\s+$/,"");

}

1 reply

try67
Community Expert
Community Expert
July 6, 2016

Is this a LiveCycle Designer form or an Acrobat form?

Known Participant
July 6, 2016

Hi again,

Acrobat Form.   If the code looks like from LiveCycle, it's because I tried an example from another Forum.

Till later,
Rick S.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 6, 2016

OK, in that case you can use this code as the custom calculation script of the Recipient field:

event.value = trim(this.getField("LastName").valueAsString) + ", " + trim(this.getField("FirstName").valueAsString);

function trim(s) {

    return s.replace(/^\s+/,"").replace(/\s+$/,"");

}