This post will discuss how to get the selected value of dropdown in JavaScript and jQuery onchange event.

1. Using jQuery

The idea is to bind the change event handler to the select box using the .change(handler) method. Now an alert is displayed whenever an option is selected from the dropdown.

jQuery


HTML



Edit in JSFiddle

 
Note that this.value won’t work with an arrow function. Use the following code instead:

jQuery


HTML



Edit in JSFiddle

 
The .change(handler) method is a shortcut for .on("change", handler). You can also do like:

jQuery


HTML



Edit in JSFiddle

2. Using JavaScript

In vanilla JavaScript, you can use the onchange property to specify an event handler to receive change events. Now, the onchange event handler is fired whenever a change is made to the select element.

HTML


JS



Edit in JSFiddle

 
Note that it is bad practice to mix JavaScript with HTML markup. A better solution would be:

JS


HTML



Edit in JSFiddle

That’s all about getting the selected value of dropdown in JavaScript and Query on change.