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

Script To Combine Text Fields

mjmurf
Registered: Jul 16 2010
Posts: 5
Answered

Hi all,

I'm fairly new to java scripting and I'm trying to write a short piece of code to combine 3 text fields into one.

I have three fields; Surname, Firstname and Middlename. I want to be able to combine the three seperate fields into a single Fullname field.

ie. Fullname=Firstname+" "+Middlename+" "+Surname

Can anyone please help me with the Javascript equivalent of this and let me know which of the Fullname properties I should put the code in. (Calculate, Validation, etc)

Thanks very much!

PS: Using Acrobat 9

My Product Information:
Acrobat Pro 9.0
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You have to write a custom calculation JavaScript to perform this task.

For the 'Fullname' field, select the 'Calculate' tab and select the 'Custom calculation script' option. The simplest code that can used is:
var cFirst = this.getField('Firstname').value;var cMiddle = this.getField('Middlename').value;var cLast = this.getField('Surname').value;event.value =  cFirst + ' ' + cMiddle + ' ' + cLast;

The above code will place two spaces between the first and surname if there is no middle name.

George Kaiser

mjmurf
Registered: Jul 16 2010
Posts: 5
Thanks very much. Works great.

Everything was working fine. I saved the form using the Extend Features in Adobe Reader. Now the script doesn't seem to run. It won't automatically populate the Fullname field. I have opened the document in both Reader and Acrobat with the same results. I have deactivated the extended features and it still doesn't work. The script is still there and the field names have not changed.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
I have not problem with Acrobat or Reader versions 7 on.

Have you made the PDF an archive PDF, PDF/A?

Have your preferences to open the PDF as a PDF/A document?

You should check your application preferences and the documents properties.

George Kaiser