PDF Editing Issues

How to Combine First and Last Name in PDF Fields Using JavaScript

Bushra ParveenBushra Parveen Nov 24, 2026 869 views

Question details

The user needs to automatically combine data from distinct First Name and Last Name form fields into a single target field using JavaScript.

How to Combine First and Last Name in PDF Fields Using JavaScript
Product
PDF Editor
Device & OS
not provided
Scenario
Creating dynamic PDF forms where full names and current dates need to be generated automatically based on other input fields.
Observed behavior
The target PDF form field dynamically displays the combined First Name, Last Name, and current date based on a custom calculation script.
Before you start

Ensure you have the exact names of the source form fields (e.g., 'FirstName', 'LastName') ready, as JavaScript field referencing in PDF forms is strictly case-sensitive.

Solution 1Recommended

Use a Custom Calculation Script in PDF Form Properties

Add a JavaScript snippet to the target field's properties to automatically concatenate the names and append the current date.

This method utilizes the built-in JavaScript capabilities of advanced PDF form editors to execute a custom calculation script whenever the document fields are updated.

1
Open target field properties

Right-click the target text field where you want the combined name to appear and select 'Properties' from the context menu.

2
Navigate to the Calculate tab

In the Properties dialog box, go to the 'Calculate' tab and choose the option for 'Custom calculation script'.

3
Enter the JavaScript code

Click the 'Edit' button and paste the following code: event.value = this.getField('FirstName').value + ' ' + this.getField('LastName').value + ' , ' + util.printd('mm/dd/yyyy', new Date());

4
Adjust field names and save

Ensure that 'FirstName' and 'LastName' exactly match the names of your source form fields. Click 'OK' to save your script and close the properties window.

Use a Custom Calculation Script in PDF Form Properties
Real-time Update: Whenever a user fills in the First Name and Last Name fields, the target field will automatically update to show the combined full name and the current date.

Easily Manage and Fill PDF Forms with WPS Office

Need a lightweight and cost-effective tool to handle PDF forms? WPS Office offers a powerful built-in PDF module that lets you interact with interactive forms, add text, edit layouts, and manage your documents effortlessly.

  1. 1. Download and Install: Get WPS Office for free from the official website and launch the WPS PDF module.
  2. 2. Open your PDF Form: Click 'Open' to import the PDF document containing your interactive form fields.
  3. 3. Fill or Edit: Use the intuitive Form and Edit tools to seamlessly fill out text fields, check boxes, and manage your PDF data.
Seamlessly interact with and fill out standard PDF forms and fields.Fully compatible with Microsoft Office formats including Word, Excel, and PowerPoint.Lightweight software that quickly opens heavy PDF files.Easily add text, signatures, and annotations to any PDF document.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my PDF custom calculation script working?

The most common issue is mismatched field names. JavaScript is case-sensitive, so ensure the field names in your script perfectly match the actual names assigned to the source form fields in the PDF.

Can I remove the date from the combined PDF field?

Yes. To only combine the first and last name without the date, modify the script to: event.value = this.getField('FirstName').value + ' ' + this.getField('LastName').value;

How do I format the date differently in the PDF JavaScript?

You can change the date format string in the util.printd function. For example, changing 'mm/dd/yyyy' to 'dd-mm-yyyy' will display the date as day-month-year instead.

Do I need a specific PDF editor to run PDF JavaScript?

Most advanced PDF editors that support form creation can execute standard PDF JavaScript commands. However, some basic browser-based PDF viewers may not support automatic field calculation and might require users to open the file in a dedicated desktop application.