JavaScript Dropdown change Event

The change event runs after the user commits a new selection in a dropdown list. Use it to read the selected value and update the page without putting JavaScript directly in the HTML onchange attribute.

const month = document.getElementById("s1");
const output = document.getElementById("msg3");

month.addEventListener("change", () => {
  output.textContent = month.value;
});
Demo of listbox change event
Table of Contents

Listen for the change Event Top ↑

The original tutorial used an inline onChange handler. addEventListener() keeps behavior in JavaScript and allows more than one listener.

<select id="s1" name="month">
  <option value="Jan">January</option>
  <option value="Feb">February</option>
  <option value="Mar">March</option>
</select>
<div id="msg3" aria-live="polite"></div>

Read the Option Value or Visible Text Top ↑

const value = month.value;
const text = month.options[month.selectedIndex].text;

The value is the data assigned to the option. The text is what the visitor sees.

Use selectedIndex When the Position Matters Top ↑

selectedIndex returns the position of the selected option. Prefer stable option values for application logic because indexes change when options are inserted or reordered.

Read Multiple Selections Top ↑

A multiple-select needs a different approach because several options may be selected. Continue with multiple listbox selection.

getElementById() · add options · listbox reference · JavaScript validation

OnChange event of dropdown list box to trigger a function to reload the page with selected data



Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer