How to Automatically Fill the Last Four Digits of an SSN in a PDF Form
Question details
The user needs to dynamically extract the last four digits of a Social Security Number from a primary text field and auto-populate them into a secondary text field in a PDF form.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where users provide a full SSN once, and the form automatically fills subsequent fields requiring only the last four digits.
- Observed behavior
- The user requires a method to link two form fields so the second field automatically displays a substring of the first field's value.
Verify the exact field name of the primary SSN text box in your PDF form and ensure you are using a PDF editor that supports JavaScript for interactive form calculations.
Add a Custom Calculation Script to the Form Field
Use a simple JavaScript snippet in the secondary form field's properties to automatically extract the last four digits from the primary field.
This method utilizes standard PDF JavaScript calculation properties. By targeting the primary field's value as a string, you can extract specifically the final four characters using the substr() function.
Open your interactive PDF form in your PDF editor and activate the form editing or prepare form mode.
Right-click the secondary field (where the last four digits should appear) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab.
Select the 'Custom calculation script' option and click the 'Edit' button. Paste the following code into the script window: event.value = this.getField("SSN").valueAsString.substr(-4);
Replace 'SSN' in the script with the exact name of your primary field. Click 'OK' to save the script, then test the form by typing a number into the primary SSN field.

Create and Edit Interactive PDF Forms with WPS PDF
WPS Office offers robust PDF editing capabilities, making it incredibly easy to design interactive forms, insert text fields, and manage user data efficiently.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the dedicated PDF tab.
- 2. Access Form Tools: Navigate to the 'Form' menu on the top ribbon to reveal all interactive form controls.
- 3. Add and Configure Fields: Insert text fields or checkboxes, double-click them to configure their properties, and save your fully functional PDF form.

Frequently Asked Questions
Why doesn't the Calculate option appear in my field properties?
The Calculate tab is exclusive to standard interactive form objects like Text Fields and Dropdowns. If it is missing, confirm that you have selected a valid interactive form field and that your PDF software fully supports advanced form calculation features.
Can I use this calculation script to extract a different number of digits?
Yes. The '.substr(-4)' portion of the JavaScript snippet dictates how many characters are extracted from the end of the string. You can change '-4' to '-2', for example, to extract only the last two digits.
Does the field name in the script need to exactly match my primary field?
Yes, the field name referenced in 'this.getField("SSN")' is highly case-sensitive. It must be identical to the actual name of the text box where the full Social Security Number is entered for the script to fetch the data successfully.




