Populate an HTML Text Field from a Dropdown with JavaScript
Question details
The user wants an HTML form to display text associated with the selected dropdown option.

- 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.
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.
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.
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>.
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>
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.

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.

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.




