PDF Editing Issues

Fix Acrobat JavaScript TypeError and Undefined String Values in PDF Forms

Aamir Naveed AkramAamir Naveed Akram Nov 5, 2026 869 views

Question details

The user is encountering a TypeError due to an undefined variable when using a JavaScript string splitting function to format a currency value in a PDF form.

How to Fix Acrobat JavaScript String Splitting and Undefined Values
Product
PDF Form Editors
Device & OS
not provided
Scenario
Attempting to reformat user-inputted currency strings (e.g., converting $12,345 into 12345) using a script tied to a Mouse Enter action.
Observed behavior
A TypeError occurs because the script attempts to process an undefined value. This happens because the event.value property is invalid when used inside mouse and keyboard events.
Before you start

Ensure you have access to the form field properties and the JavaScript editor in your PDF application. It is recommended to test your scripts on a copy of the document to prevent accidental data loss.

Solution 1Recommended

Move Script to a Validation Event and Use RegEx

The most robust way to process and format form field values is to use a custom validation script combined with regular expressions instead of relying on mouse events.

The event.value property is exclusively designed for use in validation or calculation scripts. It will return undefined if called during a mouse event (like Mouse Enter or Mouse Up), which causes string splitting functions to fail.

1
Open Form Field Properties

Right-click the specific text field in your PDF form where the currency is entered and select 'Properties' from the context menu.

2
Navigate to the Validate Tab

Click on the 'Validate' tab. This is where scripts that check and format user input should reside.

3
Apply Custom Validation Script

Select the option to 'Run custom validation script' and enter the following JavaScript code: event.value = event.value.toString().replace(/[$\,]+/g, "");

4
Save and Test

Click 'OK' to close the properties window, exit form editing mode, and test the field by typing a currency value like $12,345.

Move Script to a Validation Event and Use RegEx
Format Independence: Using the regular expression replace(/[$\,]+/g, "") is superior to string splitting because it does not depend on the user typing the data in one specific rigid format.
Advanced PDF Form Editor

Easily Manage PDF Forms and JavaScript with WPS Office

WPS PDF provides comprehensive tools for creating, editing, and managing PDF forms. You can effortlessly insert interactive fields, configure properties, and test custom JavaScript validations to ensure your data formats perfectly without complex workarounds.

  1. 1. Open Your PDF Form: Launch WPS Office and open the PDF document containing your interactive forms.
  2. 2. Access Form Editing Tools: Navigate to the 'Form' tab on the top ribbon to reveal the form field management tools.
  3. 3. Edit Field Properties: Double-click the text field you wish to modify to open its Properties dialog box.
  4. 4. Add Validation Scripts: Go to the Validate or Calculate tab to input standard JavaScript, ensuring your text formats correctly on user input.
Intuitive interface for adding and editing interactive form fields.Fully compatible with standard PDF JavaScript actions and validation scripts.Lightweight software that ensures seamless viewing and filling of PDF forms.High compatibility with forms created in Adobe Acrobat and Microsoft Office.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF JavaScript return a TypeError during a mouse event?

The event.value property is not valid for mouse or keyboard events (like Mouse Enter). When triggered this way, it returns an 'undefined' value, which causes a TypeError if your script attempts to split or parse it as a string. You must use event.target.value instead.

What is the best way to remove formatting like dollar signs and commas in PDF forms?

Using a regular expression within a Validation script is the most reliable method. A simple script like event.value = event.value.toString().replace(/[$\,]+/g, ""); will automatically strip currency symbols and commas regardless of how the user formats their input.

When should I use a Validation script instead of an Action script?

Validation scripts should be used whenever you need to format, restrict, or modify the actual data a user inputs into a field. Action scripts (like Mouse Enter or Mouse Up) are better suited for triggering UI changes, such as displaying helpful tooltips or highlighting specific fields.