How to Use JavaScript to Enter Text in an Acrobat PDF Field
Question details
The user needs to populate a PDF text field by prompting a pop-up input box via JavaScript when the field is clicked.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms that require user input via custom pop-up dialog boxes.
- Observed behavior
- The user wants to collect text via a dialog box and automatically insert it into the active PDF text field upon a click or focus event.
Ensure you have a PDF editor that supports JavaScript execution and form field editing, such as Adobe Acrobat Pro, before applying custom scripts.
Use the app.response() Method in Acrobat JavaScript
Add a JavaScript action to the text field to trigger a pop-up dialog that captures and inserts the user's text.
You can use the built-in Acrobat JavaScript method app.response() to prompt the user for input. This script can be seamlessly tied to form field events like 'Mouse Up' or 'On Focus'.
Open your PDF in form editing mode. Right-click the target text field where you want the pop-up to appear and select 'Properties'.
Go to the 'Actions' tab in the Properties dialog box. Select 'Mouse Up' or 'On Focus' from the Select Trigger dropdown menu.
Choose 'Run a JavaScript' from the Select Action dropdown and click the 'Add' button.
In the JavaScript Editor, enter the following code: var value = app.response({cQuestion: "Enter text:", cTitle: "Text input"}); if (value !== null) event.target.value = value; and click OK to save.

Create and Fill PDF Forms Easily with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily create interactive forms, add text fields, and fill out PDF documents without needing to write complex JavaScript code.
- 1. Open WPS Office: Launch WPS Office and open your PDF document.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access all interactive field tools.
- 3. Add a Text Field: Click 'Text Field' and draw the box on your document where you want users to input data.
- 4. Edit Field Properties: Double-click the newly created text field to customize its appearance and default text.
- 5. Save and Distribute: Click 'Save' to preserve your interactive PDF form for users to fill out.

Frequently Asked Questions
Why isn't my PDF JavaScript pop-up working?
Your PDF viewer might have JavaScript disabled for security reasons. Go to your PDF software's Preferences, find the JavaScript category, and check 'Enable Acrobat JavaScript'.
Can I make the JavaScript text input mandatory?
Yes, you can add conditional logic to your script to check if the returned value is empty, and display an alert prompting the user to provide the required information before proceeding.
Does the app.response() method work on mobile PDF readers?
Support for interactive JavaScript like app.response() varies heavily on mobile devices. Most default mobile PDF readers do not support Acrobat JavaScript, so the pop-up may not trigger.
How do I clear the text field using JavaScript?
You can create a reset button and add a 'Mouse Up' JavaScript action with the code this.resetForm(["YourFieldName"]); to clear the specific text field.




