Skip to main content
johnnyZ
Inspiring
April 10, 2023
Answered

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

  • April 10, 2023
  • 1 reply
  • 1193 views

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?

This topic has been closed for replies.
Correct answer Nesa Nurani

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 = "";

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 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 = "";
johnnyZ
johnnyZAuthor
Inspiring
April 11, 2023

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.