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

Combining Text Fields in Acrobat Pro 6

SFCWoods
Registered: Aug 12 2008
Posts: 9
Answered

I have a form that has LastName, FirstName and MI fields on it. I have another section of the form that needs the LastName + FirstName + MI on it. All I want is a simple script that will fill the new form field FullName with the combined text of the other three fields. I can't find the solution out here and it has been a while since I tried to mess with any scripting at all. Any simple solution here?

Field Names:
LastName
FirstName
MI
FullName

Thanks,

SFC Woods

My Product Information:
Acrobat Pro 6.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
With Acrobat 4.0 Adobe provided some sample forms and in the PFN sample they included a document level function called 'fillin" that will concatinate up to 3 fields with an optional seperator:

// Concatenate up to 3 strings with an optional separator where needed

function fillin(s1, s2, s3, sep) {

// computed value to determine which strings to combine
var test = 0; // binary: 000

var string = "";

// convert passed parameters to strings
s1 = s1.toString();
s2 = s2.toString();
s3 = s3.toString();
sep = sep.toString();

// compute a unique value to deternine what specific strings to combine
if (s1 != "") test += 1; // binary: test + 001
if (s2 != "") test += 2; // binary: test + 010
if (s3 != "") test += 4; // binary: test + 100

// select combination of strings based on computed value
switch(test.toString()) {

case "0": // binary: 000
string = "";
break;

case "1": // binary: 001
string = s1;
break;

case "2": // binary: 010
string = s2;

case "3": // binary: 011
string = s1 + sep + s2;
break;

case "4": // binary: 100
string = s3;
break;

case "5": // binary: 101
string = s1 + sep + s3;
break;

case "6": // binary 110
string = s2 + sep + s3;
break;

case "7": // binary: 111
string = s1 + sep + s2 + sep + s3;
break;

} end switch text
return string;
} // end function fillin

And the custom calculation srcirpt for the name fields:

// Name only

function doFullName() {
var first = this.getField("name.first");
var initial= this.getField("name.initial");
var last = this.getField("name.last");

event.value = fillin(first.value, initial.value, last.value, " ");
}

doFullName();


And the full name with prefix, suffix and nickname:

// 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();

George Kaiser

SFCWoods
Registered: Aug 12 2008
Posts: 9
WOW! lol. That is a lot. I tried to use this code and my new field does not update:
// Name only

function doFullName() {
var first = FirstName("name.first");
var initial= MI("name.initial");
var last = LastName("name.last");

event.value = fillin(last.value, first.value, name.value, " ");
}

doFullName();

What am I doing wrong? Remember, I do not do this all of the time.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You might want to make the field names match.

The custom calculation script for "FullName":

// Name only

function doFullName() {
var first = FirstName("FirstName");
var initial= MI("MI");
var last = LastName("LastName");

event.value = fillin(last.value, first.value, name.value, " ");
}

doFullName();

When you use the "fillin()" function in the doucment level script it is not that much code because you do not need write it again no matter how many times you use it in the PDF.

George Kaiser

SFCWoods
Registered: Aug 12 2008
Posts: 9
Okay, I tried that, but the new field FullName, does not populate with anything at all, even after I move from each of the other fields.

I am not a rock, but I am not a rocket scientist either. lol I have saved that one page and can send it if you think that will help.


// Name only

function doFullName() {
var first = FirstName("FirstName");
var initial= MI("MI");
var last = LastName("LastName");

event.value = fillin(last.value, first.value, name.value, " ");
}

doFullName();
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The simplest approach might be the following as the "FullName" field's custom calculation script:

event.value = getField("LastName").value + " " + getField("FirstName").value + " " + getField("MI").value;



George
SFCWoods
Registered: Aug 12 2008
Posts: 9
Thanks George! That is exactly what I was looking for. Simple, clean and it works. THANKS
mjolnir
Registered: Apr 8 2008
Posts: 7
I have a test form with three text boxes and I used the event.value string in a custom calculation script to concatenate the first two into the third. It works great, once. If I save the form (acroform) and reopen it , it will not work untill I open the script and re-edit. I am using Acrobat 8. Any help will be appreciated.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
I'd be interested in looking at the form if you're free to e-mail it.

George
mjolnir
Registered: Apr 8 2008
Posts: 7
Thanks, George it is on the way.