Display full name without extra space (no middle name)

New Here ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

I know this is simple, but I've monkeyed with it all day.

Form has name fields: first name, middle name, last name, suffix.

I want a text box will will display this full name in other parts of the form - but without extra spaces if there is not a middle name.

 

Right now I've got this:

var s1 = getField("First Name").valueAsString; var s2 = getField("Last Name").valueAsString; var s3 = getField("Middle Name").valueAsString; var s4 = getField("Suffix").valueAsString; event.value = s1 + " " + s3 + " " + s2 + " " + s4;

 

Can anyone point me in the right direction? Any assistance is appecriated - thank you!

TOPICS
PDF forms

Views

79

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
community guidelines

correct answers 2 Correct Answers

Most Valuable Participant , Apr 05, 2021 Apr 05, 2021
You can use this code: var s1 = getField("First Name").valueAsString; var s2 = getField("Last Name").valueAsString; var s3 = getField("Middle Name").valueAsString; var s4 = getField("Suffix").valueAsString; var names = []; if (s1!="") names.push(s1); if (s2!="") names.push(s2); if (s3!="") names.push(s3); if (s4!="") names.push(s4); event.value = names.join(" ");

Likes

Translate

Translate
Adobe Community Professional , Apr 05, 2021 Apr 05, 2021
Try this: if (s3 == "") event.value = s1 + " "  + s2 + " " + s4; else event.value = s1 + " " + s3 + " " + s2 + " " + s4;

Likes

Translate

Translate
Most Valuable Participant ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

You can use this code:

 

var s1 = getField("First Name").valueAsString; 
var s2 = getField("Last Name").valueAsString; 
var s3 = getField("Middle Name").valueAsString; 
var s4 = getField("Suffix").valueAsString; 
var names = [];
if (s1!="") names.push(s1);
if (s2!="") names.push(s2);
if (s3!="") names.push(s3);
if (s4!="") names.push(s4);
event.value = names.join(" ");

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
community guidelines
New Here ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

This works - thank you so much for taking the time to reply. Thanks for sharing this!

Pete.

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
community guidelines
Adobe Community Professional ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Try this:

if (s3 == "")

event.value = s1 + " "  + s2 + " " + s4;

else

event.value = s1 + " " + s3 + " " + s2 + " " + s4;

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
community guidelines
New Here ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

Hi Bernd - thank you so much! This also works and I really appreciate you taking your time and expertise to answer me. Thanks again!

Pete.

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
community guidelines