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

Split Field: First Name and Last Name

hunths
Registered: Aug 9 2007
Posts: 9

I have created a letter that has a field that contains both the first and last name of the individual that the letter is being sent to. The body of the letter begins with, "Dear _____." I need to create a field after "Dear" that will pull only the first name from the other field that is composed of both the first and last name. Hopefully there is an easy answer for this. I have searched and searched and haven't found out how to do it. Thanks for any help.

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
The preferred technique would be to create individual fields at lowest break out and then create (compute) the combined values. For an example of this in Acrobat Forms, see the PFN folder on the Acrobat distribution CD-ROM. Assuming the first name has not spaces, that is not a double name, one can use the JavaScript method of "split(' ')" to convert the full name into an array of names split at the space between the names.

George Kaiser

hunths
Registered: Aug 9 2007
Posts: 9
Unfortunately I don't have the Acrobat Distribution CD-ROM. The letter should first ask the user to enter the person's first and last name into one field (unless there is some way to trim the first field so the second field would begin to print immediately after the first field). I have been playing around with the "Split" feature and cannot get it to work. Since I'm not a programmer, I still need more detailed help on how to accomplish this. Thanks for any help.

Example of beginning of letter:

Bob Smith
123 Main Street
Los Angeles, CA 90012

Dear Bob:
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
I assume you are using LveCycle Designer, a seperate and distinct program form Acrobat and Acrobat Forms as are the forms that they create. Assuming the user enters their first and last name into a field called "Name". You will have to use JavaScript and not FormCalc:

// first name field calculation script
var aName = new Array(); // define an array for the names
aName = Name.rawValue.split(" "); // populate aName array with names
$.rawValue = aName[0];

// last name field calculation script
var aName = new Array(); // define an array for the names
aName = Name.rawValue.split(" "); // populate aName array with names
$.rawValue = aName[1];

George Kaiser

hunths
Registered: Aug 9 2007
Posts: 9
Sorry for my long response below.

I am using Acrobat Professional 8.0 and have used its Forms feature to create all of my documents. I have never used LiveCycle Designer.

When I create a field on a form, I have a number of properties available to me. One of the tabs in the field's properties is called "Calculate." On this tab I have several options available to me: (1) value is not calculated. (2) value is the sum, product, average, minimum, or maximum. (3) a Simplified Field Notation, (a JavaScript editor). (4) a custom calculation script where you can create and edit JavaScripts. It is this 4th area that I have attempted to write JavaScript. In the past I have been able to find scripts to automatically populate the current date.

My field that currently holds both the person's first and last name has been named "Name." My next field's name is "Dear" and should pull only the first name from the "Name" field. At one point several months ago, I was able to find a script that did this but also included a : after the person's first name. I would like to be able to do this.

I played around with the calculation script below and can't get it to work for me. I'm not sure what I'm supposed to put where. Any chance you can provide a little more detailed response. Again, I'm not a programmer so I'm really struggling here.

// first name field calculation script
var aName = new Array(); // define an array for the names
aName = Name.rawValue.split(" "); // populate aName array with names
$.rawValue = aName[0];

// last name field calculation script
var aName = new Array(); // define an array for the names
aName = Name.rawValue.split(" "); // populate aName array with names
$.rawValue = aName[1];
hunths
Registered: Aug 9 2007
Posts: 9
I have finally gotten the form to do what I want it to do. Here are the details for anyone who may wish to do what I am doing.

I called my first field "name.firstlast" (which will hold both the first and last names).

I called my second field "Name.FirstLast" (which will pull only the first name from the first field).

On the Calculate tab of the second field, I selected "Custom calculation script" and entered the following:

// -- start code
// use the Regular Expression to split on first space
// get first and last name(s)
var cName = this.getField("name.firstlast").valueAsString;
// Regular Expression for first and last name(s) separated by a space
re = /(\w+)\s(\w+)/;
// set event value to first name9s0 only
event.value = cName.replace(re,"$1")+":"
// ---> end code