To get the selected option value on change from a dropdown using jQuery, the simplest way is to use the jQuery change method, jQuery find() method, and jQuery val() method.

$('#dropdown').on('change', function() {
  var selected_option_value = $(this).find(":selected").val();
});

To get the selected option text on change from a dropdown using jQuery, the simplest way is to use the jQuery change method, jQuery find() method, and jQuery text() method.

$('#dropdown').on('change', function() {
  var selected_option_value = $(this).find(":selected").text();
});

Let’s say I have the following HTML:

To get the selected option on change from the dropdown, and display the selected option’s value and the selected option’s text, we can use the jQuery change() method combined with the val() method and jQuery text() method with the following Javascript code:

$('#select-list').on('change', function() {
  var selected_option_value = $(this).find(":selected").val();
  var selected_option_text = $(this).find(":selected").text();
});

If you are using WordPress, don’t forget to change the $ to jQuery as below:

jQuery('#select-list').on('change', function() {
  var selected_option_value = jQuery(this).find(":selected").val();
  var selected_option_text = jQuery(this).find(":selected").text();
});

How to Get Selected Option On Change using jQuery

Many times when creating a web page and the user experience, we want to read the user inputs when a user interacts with another element on the web page.

We can get the selected option value on change from a dropdown using jQuery very easily by combining the change() method with the val() and text() methods.

Let’s say we have the following HTML code and we want to show the selected option’s value and text in a paragraph. We will change the text in the spans below on change.

Select an option to show the value and text of that option.

The selected option's value is: , and the selected option's text is .

We can utilize the jQuery change() method, jQuery val() method, and jQuery text() method to get the text of the selected option, and value of the selected option on change.

Below is the Javascript code which will allow the user to be able to get the selected optionusing jQuery:

$('#select-list').on('change', function() {
  $("#selected-value").text($(this).find(":selected").val());
  $("#selected-text").text($(this).find(":selected").text());
});

The final code and output for this example of how to get the selected option from a dropdown on change using jQuery and Javascript is below:

Code Output:

Select an option to show the value and text of that option.

The selected option’s value is: , and the selected option’s text is .

Full Code:


Select an option to show the value and text of that option.

The selected option's value is: , and the selected option's text is .

<script> $('#select-list').on('change', function() { $("#selected-value").text($(this).find(":selected").val()); $("#selected-text").text($(this).find(":selected").text()); }); </script>

Hopefully this article has been useful for you to understand how to use jQuery to get the selected value on change from a dropdown.

Categorized in:

jQuery,

Last Update: March 21, 2024