Use Acrobat JavaScript to Remove Digits from a PDF Form Field
Question details
Copy the six middle digits of a nine-digit PDF form value into another form field.

- 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.
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".
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.
In Acrobat, open the PDF and select All tools > Prepare a form.
Double-click the "New ID" field, then open the Calculate tab in its properties.
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 = "";
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".

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.

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.




