Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to trim and concatenate two text fields in a form

New Here ,
Jul 06, 2016 Jul 06, 2016

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

TOPICS
Acrobat SDK and JavaScript , Windows
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 06, 2016 Jul 06, 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+$/,"");

}

Translate
Community Expert ,
Jul 06, 2016 Jul 06, 2016

Is this a LiveCycle Designer form or an Acrobat form?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2016 Jul 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2016 Jul 06, 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+$/,"");

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2016 Jul 06, 2016

Hi again,

Excellent !!   Will test and report back shortly.

Much appreciated & till later,
Rick S.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2016 Jul 06, 2016
LATEST

Hi again,

That worked perfectly.   I'd also like to include the Middle Initial field... but I'll try to do that using your example to learn from... will only ping again if unable to solve.

Very much appreciated & till later,
Rick S.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines