PDF Editing Issues

Populate an HTML Text Field from a Dropdown with JavaScript

Amos GikundaAmos Gikunda Nov 19, 2026 868 views

Question details

The user wants an HTML form to display text associated with the selected dropdown option.

Populate an HTML Text Field from a Dropdown with JavaScript
Product
HTML forms and JavaScript
Device & OS
not provided
Scenario
A dropdown selection should populate another field with the corresponding rules or text.
Observed behavior
The destination field should update whenever the dropdown selection changes.
Before you start

Confirm that the target is an HTML form rather than a PDF form. Identify the dropdown option values and the text each selection should display.

Solution 1Recommended

Update an HTML field when the dropdown selection changes

Use a JavaScript mapping and a change event listener to display the text associated with each dropdown value.

1
Add the form elements

In your HTML file, add a dropdown and a destination field: <select id="choice"><option value="">Choose an option</option><option value="a">Option A</option><option value="b">Option B</option></select><textarea id="rules" readonly></textarea>.

2
Add the mapping and listener

After the form elements, add: <script>const textByChoice = { a: 'Rules for option A', b: 'Rules for option B' }; const choice = document.getElementById('choice'); const rules = document.getElementById('rules'); function updateRules() { rules.value = textByChoice[choice.value] || ''; } choice.addEventListener('change', updateRules); updateRules();</script>

3
Customize and test

Replace the option values and mapping text with your own, then open the HTML page in a browser and select each dropdown option. The textarea should update or clear when the placeholder is selected.

Update an HTML field when the dropdown selection changes
HTML and PDF scripts differ: Acrobat form scripts use a different form API and cannot be copied directly into an HTML form. Use browser JavaScript and HTML element IDs for the web version.
Free Microsoft Office alternative

Work with Office documents and PDFs 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 bring existing files across. Use its PDF tools to review forms; the HTML dropdown automation in this article still requires JavaScript in a web page.

Review PDF forms alongside your other documentsOpen common Microsoft Office formats, including DOCX, XLSX, and PPTXNavigate documents with a familiar, easy-to-use interfaceUse a free, lightweight suite for everyday office tasks
microsoft office alternative - wps office

Frequently Asked Questions

Can I populate a single-line input instead of a textarea?

Yes. Replace the textarea with <input id="rules" type="text" readonly> and keep the same JavaScript assignment to rules.value.

How do I clear the field when no option is selected?

Give the placeholder option an empty value and use textByChoice[choice.value] || '' when assigning the destination field. This clears it when there is no matching text.

Can users edit the populated text?

Yes. Remove the readonly attribute from the input or textarea. A later dropdown change will replace any edits with the mapped text.

Will an Acrobat dropdown script work in an HTML form?

Not directly. Acrobat scripts use PDF form APIs, while an HTML page uses browser APIs such as document.getElementById and addEventListener.