Truncate a field (Name) to create Initials

Community Beginner ,
Apr 23, 2019

Copy link to clipboard

Copied

Hi - I am brand new at this... Please be gentle.

I have an Acrobat form with a persons name in two fields. (First name and Last name) I would like to automatically create a third read only field with just the first letters of each name.

Any ideas? Thanx

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

Yes, a script like this will work. Put it in the calculation event.

var cFName = this.getField("First Name").value;

var cLName = this.getField("Last Name").value;

event.value = ((cFName.length)?cFName[0]:"") + ((cLName.length)?cLName[0]:"");

TOPICS
Acrobat SDK and JavaScript, Windows

Views

417

Likes

Translate

Translate

Report

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

Truncate a field (Name) to create Initials

Community Beginner ,
Apr 23, 2019

Copy link to clipboard

Copied

Hi - I am brand new at this... Please be gentle.

I have an Acrobat form with a persons name in two fields. (First name and Last name) I would like to automatically create a third read only field with just the first letters of each name.

Any ideas? Thanx

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

Yes, a script like this will work. Put it in the calculation event.

var cFName = this.getField("First Name").value;

var cLName = this.getField("Last Name").value;

event.value = ((cFName.length)?cFName[0]:"") + ((cLName.length)?cLName[0]:"");

TOPICS
Acrobat SDK and JavaScript, Windows

Views

418

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 23, 2019 0
Most Valuable Participant ,
Apr 23, 2019

Copy link to clipboard

Copied

You can use something like this as the custom calculation script of the initials field:

var fullName = this.getField("First name").valueAsString + " " + this.getField("Last name").valueAsString;

var words = fullName.split(" ");

var initials = "";

for (var i in words) initials+=words.charAt(0).toUpperCase();

event.value = initials;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2019 1
Adobe Community Professional ,
Apr 23, 2019

Copy link to clipboard

Copied

Yes, a script like this will work. Put it in the calculation event.

var cFName = this.getField("First Name").value;

var cLName = this.getField("Last Name").value;

event.value = ((cFName.length)?cFName[0]:"") + ((cLName.length)?cLName[0]:"");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2019 1
try67 LATEST
Most Valuable Participant ,
Apr 23, 2019

Copy link to clipboard

Copied

That will work, but only if each name is only one word. If the first name is "John Paul" and the last name is "George", for example, it will only return "JG", not "JPG".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2019 0