PDF Editing Issues

How to Use an Acrobat JavaScript LEFT Formula Equivalent in PDF

Huma Ashraf ChHuma Ashraf Ch Oct 28, 2026 869 views

Question details

The user needs to create a calculated testing ID in a fillable PDF by extracting specific characters from first-name, last-name, and birthday fields using an Acrobat JavaScript equivalent to the LEFT formula.

Product
PDF
Device & OS
not provided
Scenario
Setting up a fillable PDF form that automatically generates a unique testing ID based on substrings extracted from the user's input in other text fields.
Observed behavior
JavaScript is required to extract a set number of characters from the beginning or end of multiple string values and concatenate them into a target ID field.
Before you start

Ensure your PDF form already contains the exact text fields (e.g., 'First Name', 'Last Name', and 'Birthday') necessary for the calculation before you apply the custom script to the target ID field.

Solution 1Recommended

Use the JavaScript substr() Method in Custom Calculation Scripts

Since JavaScript does not have a native 'LEFT' function like Excel, you can use the substr() method to extract characters from specific positions in your PDF form fields.

The substr() method allows you to define a starting position and the number of characters to extract. For a 'LEFT' formula equivalent, you start at index 0. You can also use a negative starting index to extract characters from the end of a string, acting as a 'RIGHT' formula equivalent.

1
Access Target Field Properties

Open your PDF form editor, right-click the target field where you want the ID to appear (e.g., 'Testing ID'), and select 'Properties' from the context menu.

2
Navigate to the Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab to view calculation options.

3
Enter the Custom Script

Select the 'Custom calculation script' radio button, click 'Edit', and enter this script: event.value = (this.getField('Last Name').valueAsString.substr(0,3) + this.getField('First Name').valueAsString.substr(0,2) + this.getField('Birthday').valueAsString.substr(-2)).toUpperCase();

4
Save and Test the Form

Click 'OK' to save the script and close the Properties window. Test the form by typing values into the Name and Birthday fields to ensure the ID automatically generates (e.g., producing SMIJA80).

Use the JavaScript substr() Method in Custom Calculation Scripts
Understanding the Code: In the provided script, substr(0,3) acts as the LEFT function, extracting the first 3 characters. The substr(-2) extracts the last 2 characters from the Birthday field, and toUpperCase() ensures the final ID is fully capitalized.
Edit PDF Forms Easily

Create and Manage PDF Forms with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to effortlessly create fillable forms, manage text fields, and configure interactive document properties.

  1. 1. Open PDF Form in WPS Office: Launch WPS Office and open your existing PDF document or create a new one.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the form editing toolset.
  3. 3. Add Necessary Text Fields: Click 'Text Field' and draw boxes for the Last Name, First Name, Birthday, and the target ID fields.
  4. 4. Configure Properties: Double-click the target ID field to open its properties, where you can modify field names, appearance, and formats to ensure compatibility with your data.
Easily add, edit, and format fillable PDF form fieldsHighly compatible with Adobe Acrobat PDF forms and propertiesLightweight, fast, and features a user-friendly interface for document managementCross-platform support for Windows, Mac, and mobile devices
QA img-9

Frequently Asked Questions

Why isn't my PDF JavaScript calculation updating automatically?

Ensure that the calculation order is set correctly in your PDF form properties. The source fields (like Name and Birthday) must be processed before the target ID field. You can adjust the calculation order in the form editing menu.

Can I use the substring() method instead of substr() in Acrobat JavaScript?

Yes, substring(0,3) can also be used to extract the first three characters, serving as a LEFT formula equivalent. However, substr() is often preferred when you also need to extract from the end of a string using a negative starting index.

How do I handle empty fields in my PDF calculation script?

To prevent errors or partially generated IDs when the form is incomplete, wrap your extraction script in an 'if' statement that checks if the source fields are empty (e.g., if(this.getField('Last Name').valueAsString !== '') before generating the ID.