Expand my Community achievements bar.

Combining 2 text fields to create a third field

Avatar

Level 1

Hi all

I am new to the Adobe arena so I hope that some one can please lead me to accomplish this task.

I have 2 text fields last name & first name

I would like to have it create a third field with the last name, (first character of the first name field) and placing a comma after the last name.

Thank you

James

9 Replies

Avatar

Level 10

Hi,

You would place the script in the calculate event of the third field.

This should get you close (you will need to change the object references to suit the names of your objects):

I will use JavaScript:

if (lastName.rawValue !== null && firstName.rawValue !== null) {

     this.rawValue = lastName.rawValue + ", " + firstName.rawValue.toString().slice(0,1);

}

You may not need the .toString() bit, but give it a try.

Niall

Avatar

Level 1

Hi Niall,

I placed your script into the custom calculation script and rename my

fields to match what is in the script however for some reason in the new

field nothing came out. All fields are text.

Any idea?

Thanks

James

Avatar

Level 10

Sounds like you are designing your form in Acrobat and NOT LC Designer. Is that correct?

AcroForms use a slightly different syntax (closer to Core JavaScript).

Niall

Avatar

Level 1

Hi Niall, I was using the form editor, is there a difference, I am using

Adobe X Pro.

James

Avatar

Level 10

Hi James,

Yes, it does. LC Designer creates different forms and has different JavaScript syntax. You are in the LC Designer forum and your query may be better answered in an Acrobat forum.

The following script should work in an AcroForm (fingers crossed):

var i = this.getField("firstName");

var j = this.getField("lastName");

var k = this.getField("combinedName");

if (i.value !== null && j.value !== null) {

     k.value = j.value + ", " + i.value.toString().slice(0,1);

}

As before, you will need to change the object references to suit your form.

Hope that helps,

Niall

Avatar

Level 6

I revised Niall's script some to make it work as a custom calculation script and make it a bit more suitable for an Acroform:

// Get the field values, as strings

var i = this.getField("firstName").valueAsString;

var j = this.getField("lastName").valueAsString;

// Set this field's value if both fields are not blank

// otherwise, set this field to blank

if (i && j) {

     event.value = j + ", " + i.slice(0, 1);

} else {

     event.value = "";

}

(An acroform field value will never be equal to null.)

Avatar

Level 1

Hi All,

I do not know what is going on however, still nothing comes up....

Thanks

Avatar

Level 6

The code posted assumes your fields are named "firstName" and"lastName". If your fields are named something else, you'll have to use the exact field names. You can also check for errors in the JavaScript console (Ctrl+j). It is written to be a custom calculate script, so make sure it's in the right place. It will get triggered whenever any field value changes.