Fix Acrobat JavaScript TypeError and Undefined String Values in PDF Forms
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.

- 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.
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.
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.
Right-click the specific text field in your PDF form where the currency is entered and select 'Properties' from the context menu.
Click on the 'Validate' tab. This is where scripts that check and format user input should reside.
Select the option to 'Run custom validation script' and enter the following JavaScript code: event.value = event.value.toString().replace(/[$\,]+/g, "");
Click 'OK' to close the properties window, exit form editing mode, and test the field by typing a currency value like $12,345.

Use event.target.value for Mouse Actions
If your workflow absolutely requires the script to trigger on a mouse event, you must change how the field's value is targeted in the code.
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. Open Your PDF Form: Launch WPS Office and open the PDF document containing your interactive forms.
- 2. Access Form Editing Tools: Navigate to the 'Form' tab on the top ribbon to reveal the form field management tools.
- 3. Edit Field Properties: Double-click the text field you wish to modify to open its Properties dialog box.
- 4. Add Validation Scripts: Go to the Validate or Calculate tab to input standard JavaScript, ensuring your text formats correctly on user input.

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.




