These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Splitting a Person’s Name

DannyBoy
Registered: May 15 2011
Posts: 8

A have an Acrobat form that has a field named “Name_1” in which a client would put in there full name. However in a different page it asks for their name again, but it is split. Last Name & First Name. My field names are “LastNameRow1” & “FirstNameRow2” I wanted to know if there was a way to send the data from “Name_1” and split it to the other 2.
 
I know some people might have 2 first names, or even 2 last names. Plus middle initials. So I don’t know how complicated that would be. However I would be happy if it transferred the first word into the first name, and the last word into the last name. But also if it could be editable in case, for example, the person has two last names. That would be best case scenario. I’m new to Javascripts, but I’ve been working with them. Any ideas on how I could do this.
 
Thank you

My Product Information:
Acrobat Pro 9.4.3, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Why not have them complete fields for the first and last name and then combine them for the Name_1 field.

George Kaiser

DannyBoy
Registered: May 15 2011
Posts: 8
I wish I could but they are at the end of the form I have. It would not be user friendly to do that. It not something I created and I can’t change it. The combined field “Name_1” is at the beginning of the form. My other thought was, if when you enter “Name_1” could a pop up automatically come up with 3 fields for (First name, MI, and Last Name) and once they hit tab on Last name the pop up would close and go to the next field? Those 3 fields would be hidden in the document, but could only be seen in the pop up. Thus being able to send the individual data to my “FirstNameRow1” & “LastNameRow1” Any thought could that be done?
DannyBoy
Registered: May 15 2011
Posts: 8
Also those 3 fields would be able to combine them to "Name_1"? I know how complex splitting could be. I just thought having them separate from the beginning and then combining them for Name_1 would probably be easier. I just don’t know how to do that pop up box with the 3 fields. And what is the Javascript to combine them?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I don't see a practical way of knowing when a person has 2 first names or 2 family names, unless the latter are always separated by a hyphen.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can use a product like arodialogs, look at the form wizard example, to gather the information and then you can use the sample function 'fillin' provided with the Acrobat full product distribution disk in the sample forms for the "PFN".The document level function:

// Concatenate 3 strings with separators where needed
function fillin(s1, s2, s3, sep) {

/*
Purpose: concatenate up to 3 strings with an optional separator

inputs:
s1: required input string text or empty string
s2: required input string text or empty string
s3: required input string text or empty string
sep: optional separator sting

returns:
sResult concatenated string
*/

// variable to determine how to concatenate the strings
var test = 0; // all strings null
var sResult; // re slut string to return

// force any number string to a character string for input variables
s1 = s1.toString();
s2 = s2.toString();
s3 = s3.toString();
if(sep.toString() == undefined) sep = ''; // if sep is undefined force to null

/*
assign a binary value for each string present
so the computed value of the strings will indicate which strings are present
when converted to a binary value
*/
if (s1 != "") test += 1; // string 1 present add binary value: 001
if (s2 != "") test += 2; // string 2 present add binary value: 010
if (s3 != "") test += 4; // string 3 present add binary value: 100

/* return appropriate string combination based on
calculated test value as a binary value
*/
switch (test.toString(2)) {

case "0": // no non-empty strings passed - binary 0
sResult = "";
break;

case "1": // only string 1 present - binary 1
sResult = s1;
break;

case "10": // only string 2 present - binary 10
sResult = s2;
break;

case "11": // string 1 and 2 present - binary 10 + 1
sResult = s1 + sep + s2;
break;

case "100": // only string 3 present - binary 100
sResult = s3;
break;

case "101": // string 1 and 3 - binary 100 + 001
sResult = s1 + sep + s3;
break;

case "110": // string 2 and 3 - binary 100 + 010
sResult = s2 + sep + s3;
break;

case "111": // all 3 strings - binary 100 + 010 + 001
sResult = s1 + sep + s2 + sep + s3;
break;

default: // any missed combinations
sResult = "";
break;
}

return sResult;
}

The custom calculation script to build a full name:

// All name fields concatenated, with some nice formatting.

function doCompleteName() {
var prefix = this.getField("name.prefix");
var first = this.getField("name.first");
var initial = this.getField("name.initial");
var last = this.getField("name.last");
var suffix = this.getField("name.suffix");
var nickname= this.getField("name.nickname");

var result1 = fillin(prefix.value, first.value, initial.value, " ");
if (nickname.value != "")
var result2 = fillin(last.value, suffix.value, "\"" + nickname.value + "\"", " ");
else
var result2 = fillin(last.value, suffix.value, "", " ");
event.value = fillin(result1, result2, "", " ");
}

doCompleteName();

The fillin function automatically adjust for missing data or null elements.

George Kaiser