PDF Editing Issues

Use Acrobat JavaScript to Remove Digits from a PDF Form Field

Maira MehtabMaira Mehtab Nov 19, 2026 869 views

Question details

Copy the six middle digits of a nine-digit PDF form value into another form field.

Remove Digits from a PDF Form Field with Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form contains an ID field, and a second field should display its value without the first digit and final two digits.
Observed behavior
The destination field should display six middle digits when the source value has nine characters and otherwise remain blank.
Before you start

Open the PDF in Adobe Acrobat and make sure you can edit its form fields. Confirm the source and destination field names in Prepare a Form; the example uses "ID Field" and "New ID".

Solution 1Recommended

Add a custom calculation script to the destination field

Use this method to automatically copy the middle six characters from a nine-character ID into another PDF form field.

1
Open the form editor

In Acrobat, open the PDF and select All tools > Prepare a form.

2
Open the destination field properties

Double-click the "New ID" field, then open the Calculate tab in its properties.

3
Enter the calculation script

Select Custom calculation script, click Edit, and enter: var oldId = this.getField("ID Field").valueAsString; if (oldId.length == 9) event.value = oldId.substr(1, 6); else event.value = "";

4
Save and test the form

Click OK to close the script editor and field properties, save the PDF, and enter a nine-digit value in "ID Field". For example, 123456789 should produce 234567 in "New ID".

Add a custom calculation script to the destination field
The script checks length, not character type: The script accepts any nine characters. If the source must contain digits only, apply digit validation to the source field or add a digit check to the script.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. Its format compatibility helps you move existing documents into WPS; use Acrobat for the custom JavaScript calculation described above.

Open and work with PDF documents alongside Office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface makes the switch from Microsoft Office easierFree and lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

What happens if the ID has fewer or more than nine characters?

The script sets the destination field to an empty value. Enter exactly nine characters in "ID Field" to populate "New ID".

Will the script preserve a zero in the middle of the ID?

Yes. The script reads the source with valueAsString, so zeros within the six extracted characters are preserved as text.

What should I change if my field names are different?

In the destination field's Calculate tab, edit the script and replace "ID Field" with the exact name of your source field. Apply the script to whichever field should display the result.

Why is the destination field not updating?

Check that the source field name matches the name in the script and that the source value has nine characters. In Acrobat Preferences > Forms, also check that automatic field-value calculation is enabled.