Create PDF Form Fields from Dropdowns or Multiline Text in Adobe Acrobat
Question details
Create PDF form fields from multiline text or display a field associated with a dropdown selection without creating duplicates.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- A form author wants to generate fields from lines of text or show a field corresponding to a selected dropdown value.
- Observed behavior
- Each text line should produce at most one named field, or only the field matching the selected dropdown value should be visible.
Open the PDF in Adobe Acrobat Pro and choose All tools > Prepare a form. Confirm the exact names of the source and target fields, and make sure the page has enough space for any fields you create.
Create fields from multiline text with a button action
Use a button to generate fields on demand and check existing names before adding them.
This example creates text fields on the first page, using one nonblank line per field name. It replaces non-word characters with underscores, so different lines that normalize to the same name share a field.
In All tools > Prepare a form, open the multiline text field's Properties and name it multilinetext. On the Options tab, enable Multi-line.
Add a button in Prepare a form, open its Properties, and select Actions. Choose Mouse Up as the trigger, select Run a JavaScript, and click Add.
Paste this script into the JavaScript editor and click OK: var source = this.getField("multilinetext"); var lines = source.valueAsString.split(/\r\n|\r|\n/); var row = 0; for (var i = 0; i < lines.length; i++) { var line = lines[i].replace(/^\s+|\s+$/g, ""); if (!line) continue; var name = "FieldFor_" + line.replace(/[^\w]/g, "_"); var field = this.getField(name); if (!field) { var top = 530 - row * 30; field = this.addField(name, "text", 0, [149, top, 248, top - 24]); row++; } if (field) field.value = line; }
Close the Properties dialog, enter a few lines in multilinetext, and click the button. Click it again to verify that existing field names are reused rather than added again.

Show a precreated field for the selected dropdown value
Use this approach when only the field associated with the current dropdown choice should be visible.
Work with PDF documents and Office files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move between documents and PDF work. Acrobat-specific form JavaScript still requires a compatible PDF form editor.

Frequently Asked Questions
Where should I put the script that creates fields from text?
In Acrobat Pro, add a button under All tools > Prepare a form. Open its Properties > Actions, choose Mouse Up and Run a JavaScript, and add the script there so it runs on demand rather than during every calculation.
How does the script avoid creating duplicate fields?
It calls this.getField(name) before this.addField. If a field with that name already exists, the script reuses it. Lines that normalize to the same name also share a field.
Can I show only the field for the selected dropdown option?
Yes. Create the target fields in Prepare a form, then add a custom script under the dropdown's Properties > Validate tab. Map each export value to a field name and set the matching field to display.visible and the others to display.hidden.
Why do my generated fields overlap or appear off the page?
The addField rectangle uses page coordinates in PDF points. Adjust the left, top, right, and bottom values in the button script, and ensure the page has enough room for the number of lines.




