How to get selected value of dropdown in JavaScript/jQuery on change?

Today, We want to share with you get selected value of dropdown in javascript onchange.In this post we will show you javascript get selected option, hear for javascript select onchange get text we will give you demo and example for implement.In this post, we will learn about JQuery Get Dropdownlist Selected Value Onchange Event with an example.

How to get selected value of dropdown in JavaScript/jQuery on change?

using 1. jQuery Code

jQuery source code

$(document).ready(function() {
  $('select').change(function() {
    alert(this.value);
  });
});

HTML CODE

<select name="choice">
  <option value="all" selected>Choose a Value</option>
  <option value="user">User Value</option>
  <option value="client">Client Value</option>
  <option value="visitor">Visitor Value</option>
</select>

Example 2: jquery code

$(document).ready(function() {
  $('select').change(e => alert(e.target.value));
});

HTML code

<select name="choice">
  <option value="all" selected>Choose a Value</option>
  <option value="user">User Value</option>
  <option value="client">Client Value</option>
  <option value="visitor">Visitor Value</option>
</select>

Example 3: jquery code

$(document).ready(function() {
  $('select').on('change', function() {
    alert(this.value);
  });
});

HTML code

<select name="choice">
  <option value="all" selected>Choose a Value</option>
  <option value="user">User Value</option>
  <option value="client">Client Value</option>
  <option value="visitor">Visitor Value</option>
</select>

using 2. JavaScript

Example 1: HTML

<select id="choice" onchange="getValue(this);">
  <option value="all" selected>Choose a Value</option>
  <option value="user">User Value</option>
  <option value="client">Client Value</option>
  <option value="visitor">Visitor Value</option>
</select>

javaScript Code

function getValue(option) {
  alert(option.value);
}

Example 2: js code

document.getElementById('choice').onchange = function() {
  alert(this.value);
}

HTML Code

<select id="choice">
  <option value="all" selected>Choose a Value</option>
  <option value="user">User Value</option>
  <option value="client">Client Value</option>
  <option value="visitor">Visitor Value</option>
</select>

I hope you get an idea about javascript select onchange get option text.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.