Combine PDF Form Fields in Adobe Acrobat Without a Trailing And
Question details
Combine two PDF form name fields while displaying “and” only when both fields contain a name.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- A calculated PDF form field combines two defendant name fields.
- Observed behavior
- The calculated field displays an unnecessary trailing “and” when the second name field is empty.
Open the PDF in a version of Adobe Acrobat that can edit form fields. Check the exact names of the two source fields in Prepare a Form, because the script must match them.
Use a Custom Calculation Script to Join Nonempty Name Fields
Add nonempty names to a list and join them with “and” in the calculated field.
Open the PDF in Adobe Acrobat and select All tools > Prepare a form.
Double-click the field that should display the combined names, then select the Calculate tab.
Select Custom calculation script, click Edit, and enter: var names = []; var name1 = this.getField("Defendant1 Name").valueAsString; if (name1 != "") names.push(name1); var name2 = this.getField("Defendant2 Name").valueAsString; if (name2 != "") names.push(name2); event.value = names.join(" and ");
Click OK to save the script, close the field properties, and preview the form. Enter both names, then clear either name to verify that “and” appears only between two nonempty values.

Work With PDFs and Office Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Office files and PDFs. It can help you move between document formats, but it does not replace Adobe Acrobat for configuring this custom calculation script; test scripted forms in your intended PDF viewer.

Frequently Asked Questions
What happens if only one name field is filled in?
The calculated field displays that name without “and.” The script adds only nonempty values to the list before joining them.
Where do I find the exact names of my PDF form fields?
In Adobe Acrobat, open All tools > Prepare a form and check the field names in the form editor. Use those exact names inside the getField calls.
Why does the result still include an unwanted separator?
Check whether a source field contains spaces rather than being truly empty. The supplied script checks for an empty string, so spaces count as a value.
Will the calculation work in every PDF viewer?
Not necessarily. PDF viewers differ in their support for form JavaScript and calculations. Test the saved form in the viewer your recipients will use.




