Other PDF Issues

Use app.response Input with a PDF Form Field in Adobe Acrobat

Natalie TaylorNatalie Taylor Nov 19, 2026 869 views

Question details

Use input returned by app.response in an Acrobat PDF script and access a form field correctly.

Use app.response Input with a PDF Form Field in Adobe Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF script asks the user for a label count and may use that count in a loop or display it in a form field.
Observed behavior
The script needs to distinguish the input returned by app.response from the field object returned by getField.
Before you start

Open the PDF in Adobe Acrobat and confirm that JavaScript is enabled in Acrobat Preferences. If you want to write the response to a field, check its exact name in Prepare a form.

Solution 1Recommended

Store the Acrobat Form Field Object and Use the Response Separately

Use this approach when a script needs both the user's input and access to a PDF field's value or properties.

app.response returns the entered text, or null if the user cancels. this.getField returns a field object; use its value or valueAsString property to read its contents, and keep the object itself to change field properties.

1
Check the field name

Open the PDF in Acrobat, choose Prepare a form, and verify that the field is named labels. If it has a different name, use that exact name in the script.

2
Add the script

Open Acrobat's JavaScript console or the appropriate document script editor. Use code such as: var response = app.response("How many labels?"); var f = this.getField("labels"); if (response !== null) { response = response.trim(); if (!/^\d+$/.test(response)) { app.alert("Enter a whole number."); } else if (!f) { app.alert("The labels field was not found."); } else { var count = parseInt(response, 10); f.value = count; f.textSize = 12; // Use count in your label-processing loop. } }

3
Test the prompt

Run the script in the console or through its configured document event. Enter a whole number and check that the labels field displays it; also test Cancel and an invalid entry.

Store the Acrobat Form Field Object and Use the Response Separately
Reading an existing field: Use f.value or f.valueAsString after confirming that f exists. Assigning this.getField("labels").value to f stores the value, not the field object, so you cannot use f to set field properties.
Free Microsoft Office alternative

Work with PDF and Office Files in WPS Office

WPS Office is a free, lightweight alternative for everyday PDF and Office work. Its familiar interface and format compatibility make it easy to move existing files into your workflow. Use Adobe Acrobat to develop and test Acrobat-specific JavaScript.

Open and read PDF documents alongside Office filesCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXFamiliar interface for a smooth transition from Microsoft OfficeFree, lightweight tools for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

What does app.response return when the user clicks Cancel?

It returns null. Check response !== null before trimming, converting, or using the response.

How do I read the current value of a PDF form field?

Get the field with var f = this.getField("labels"), check that f exists, and then read f.value or f.valueAsString.

Why can't I change textSize after assigning the field value to a variable?

this.getField("labels").value gives you the field's value, not the field object. Store this.getField("labels") in a variable first, then set a property such as f.textSize.

How can I use the response as a loop count?

Validate that the response contains a whole number, convert it with parseInt(response, 10), and use the resulting count as the loop limit. Handle null separately when the user cancels.