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

First Name, MI, Last Name and Suffix into one field

Participant ,
Apr 10, 2023 Apr 10, 2023

One more question (if you don't mind):

What if the Person's Name has a Middle Initial?

event.value = this.getField("First Name").valueAsString + " " + this.getField("Middle Initial").valueAsString + " " + this.getField("Last Name").valueAsString;

But, if there is "No" Middle Initial, there will be 2 spaces between the First and Last Name

Similarly, I have a "Suffix" field, (ex. John Q. Public, Sr.)

I'd like a (.) period if there is a Middle Initial and a comma if there IS a suffix, but NO period or comma if there is no Middle Initial or suffix.

Is this possible?

TOPICS
Edit and convert PDFs , JavaScript , PDF forms
976
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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 10, 2023 Apr 10, 2023

Try this:

var fn = this.getField("First Name").valueAsString;
var mn = this.getField("Middle Initial").valueAsString;
var ln = this.getField("Last Name").valueAsString;
var sf = this.getField("Suffix").valueAsString;
if(fn&&mn&&ln&&sf)
event.value = fn+" "+mn+". "+ln+", "+sf;
else if(fn&&!mn&&ln&&sf)
event.value = fn+" "+ln+", "+sf;
else if(fn&&mn&&ln&&!sf)
event.value = fn+" "+mn+". "+ln;
else if(fn&&!mn&&ln&&!sf)
event.value = fn+" "+ln;
else
event.value = "";

View solution in original post

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 ,
Apr 10, 2023 Apr 10, 2023

Try this:

var fn = this.getField("First Name").valueAsString;
var mn = this.getField("Middle Initial").valueAsString;
var ln = this.getField("Last Name").valueAsString;
var sf = this.getField("Suffix").valueAsString;
if(fn&&mn&&ln&&sf)
event.value = fn+" "+mn+". "+ln+", "+sf;
else if(fn&&!mn&&ln&&sf)
event.value = fn+" "+ln+", "+sf;
else if(fn&&mn&&ln&&!sf)
event.value = fn+" "+mn+". "+ln;
else if(fn&&!mn&&ln&&!sf)
event.value = fn+" "+ln;
else
event.value = "";
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
Participant ,
Apr 10, 2023 Apr 10, 2023
LATEST

Nesa,

Thank you so very much.  It works great !!!

And you taught me something, how to do: If, Then, Else statements in Acrobat.

I marked it "Correct Answer".

Now, please don't think I'm a pervert.  I'm a very happily married man, but I saw your picture.

You have everything going for you that a smart man would want.

Beauty and brains !

Thanks again for all your help.  John.

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