How to Show a Yes/No Dialog When a PDF Text Field Reaches Its Limit
Question details
The user needs to display a confirmation dialog box when a specific PDF text field reaches its maximum character limit and dynamically shift the typing focus based on the user's Yes/No selection.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires conditional navigation and immediate feedback when a text field becomes completely full.
- Observed behavior
- The form needs a mechanism to automatically trigger an alert without requiring the user to click out of the field or press 'Enter'.
Ensure your PDF editing software supports JavaScript for interactive forms, and write down the exact names of the target fields you want to redirect focus to, as field names are case-sensitive.
Use a Custom Keystroke Script
Apply a custom JavaScript keystroke script to the text field's properties to monitor its capacity and prompt the user when the character limit is reached.
Interactive PDF forms allow you to use JavaScript to handle user events like typing. By monitoring the 'event.fieldFull' property, you can trigger an application alert immediately when the user hits the predefined character limit, shifting focus efficiently based on their response.
Open your PDF form in edit mode, right-click the text field that has a character limit, and select 'Properties' from the context menu.
Switch to the 'Format' tab. Choose 'Custom' from the format category to enable a Custom Keystroke Script.
Click 'Edit' and paste the following code into the script editor: if (event.fieldFull) { if (app.alert("Do you have a different mailing address?", 2, 2) == 4) { this.getField("Street Address").setFocus(); } else { this.getField("Agent ID").setFocus(); } }
Change 'Street Address' and 'Agent ID' in the code to match the exact names of the text fields in your document. You can also modify the question inside the app.alert function.
Click 'OK' to save the script, close the properties dialog, and switch back to viewing/filling mode to test the text field by typing until you hit the limit.

Build Interactive PDF Forms with WPS PDF
Easily design, edit, and manage interactive PDF forms with WPS Office. From inserting text fields to configuring advanced form logic, WPS PDF offers professional-grade tools to make your documents smart and efficient.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the WPS PDF component.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form creation menu.
- 3. Add and Configure Fields: Insert text fields into your document. Double-click any field to open its properties, set character limits, and apply actions.

Frequently Asked Questions
What does the app.alert function do in a PDF script?
The app.alert function displays a pop-up dialog box to the user. The parameters in the function allow you to define the message text, the icon type (such as a warning or question mark), and the button configuration (like Yes/No or OK/Cancel buttons).
Why doesn't my focus shift to the new field after clicking Yes?
Ensure that the field name specified in your 'this.getField("Field Name")' script exactly matches the actual name of the target field in the PDF form properties. Field names are completely case-sensitive and must include exact spacing.
How do I set a character limit on a PDF text field before using this script?
To set a limit, open the text field's properties, go to the 'Options' tab, check the box for 'Limit of [ ] characters', and enter your desired maximum number of characters.
Can I use 'event.fieldFull' on drop-down menus or checkboxes?
No, the 'event.fieldFull' property is specifically designed to be triggered by typing events inside a text field that has a predefined character limit. Other field types require different event triggers, such as 'Mouse Up' or 'On Blur'.




