Skip to main content
Known Participant
November 29, 2018
Question

Combining two fields into one

  • November 29, 2018
  • 1 reply
  • 1104 views

Hi, I’m creating a document with multiple forms. I’m having issues with combining the natural mother’s name and natural father’s name in a field.

On one form the names are three separate fields so I have named the fields as follows for mom’s complete name: NMFirst, NMMiddle, NMLast.

I did the same for the father’s name: NFFirst, NFMiddle, NFLast.

On another form there is one field for each parent’s complete name. For the mother I combined all three fields into one, naming that field NMName.

Again the same was done for the father, I named that field NFName.

Here is where I have run into an issue. Another form is a letter and in the address block it should have the mother’s complete name and the father’s complete name.

This is my coding:

var nm = this.getField("NMName").valueAsString;   //natural mother’s full name

var nf = this.getField("NFName").valueAsString;     //natural father’s full name

if (nf =="")event.value = nm;    //if no natural father, show natural mother’s name only

else event.value = nm + " and " + nf;   //this should show natural mother’s name and natural father’s name

This works fine until there is no natural father’s name and the result is the natural mothers name and the word “and”

Example: Megan Michelle Wright and

I’ve been looking at this for a while and trying different things to remove the word “and” but I think I’m just stuck. Thank you.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
November 29, 2018

Use this code:

if (nf=="" && nm=="") event.value = ""; //if nothing is entered, show nothing

else if (nf=="" && nm!="") event.value = nm; //if no natural father, show natural mother’s name only

else if (nf!="" && nm=="") event.value = nf; //if no natural mother, show natural father’s name only

else event.value = nm + " and " + nf; // show both

Angus24Author
Known Participant
November 29, 2018

Hi try67m thank you for the code you provide, however I get the same result of: Megan Michelle Wright and

when there is no father's name

try67
Community Expert
Community Expert
November 29, 2018

That's strange... Are you sure the field is completely empty? If it has even a single space character in it, it's no longer considered empty.

Also, where did you place the code?