jQuery Get Selected Option From Dropdown

Posted on

jQuery Get Selected Option From Dropdown – Even if we have a good project plan and a logical concept, we will spend the majority of our time correcting errors abaout javascript and html. Furthermore, our application can run without obvious errors with JavaScript, we must use various ways to ensure that everything is operating properly. In general, there are two types of errors that you’ll encounter while doing something wrong in code: Syntax Errors and Logic Errors. To make bug fixing easier, every JavaScript error is captured with a full stack trace and the specific line of source code marked. To assist you in resolving the JavaScript error, look at the discuss below to fix problem about jQuery Get Selected Option From Dropdown.

Problem :

Usually I use $("#id").val() to return the value of the selected option, but this time it doesn’t work.
The selected tag has the id aioConceptName

html code

<label for="name">Name</label>
<input type="text" name="name" id="name" />

<label for="aioConceptName">AIO Concept Name</label>
<select id="aioConceptName">
    <option>choose io</option>

Solution :

Set the values for each of the options

<label for="aioConceptName">AIO Concept Name</label>
<select id="aioConceptName">
    <option value="0">choose io</option>
    <option value="1">roma</option>
    <option value="2">totti</option>

$('#aioConceptName').val() didn’t work because .val() returns the value attribute. To have it work properly, the value attributes must be set on each <option>.

Now you can call $('#aioConceptName').val() instead of all this :selected voodoo being suggested by others.

Try this for value…

$("select#id_of_select_element option").filter(":selected").val();

or this for text…

$("select#id_of_select_element option").filter(":selected").text();

If you are in event context, in jQuery, you can retrieve the selected option element using :
$(this).find('option:selected') like this :

$('dropdown_selector').change(function() {
    //Use $option (with the "$") to see that the variable is a jQuery object
    var $option = $(this).find('option:selected');
    //Added with the EDIT
    var value = $option.val();//to get content of "value" attrib
    var text = $option.text();//to get <option>Text</option> content


As mentioned by PossessWithin, My answer just answer to the question : How to select selected “Option”.

Next, to get the option value, use option.val().

Have you considered using plain old javascript?

var box = document.getElementById('aioConceptName');

conceptName = box.options[box.selectedIndex].text;

See also Getting an option text/value with JavaScript

$('#aioConceptName option:selected').val();

For good practice you need to use val() to get value of selected options not text().

<input type="text" name="name" />
<select id="aioConceptName">
    <option value="choose">choose io</option>

You can use



   $("#aioConceptName :selected").val();

Reading the value (not the text) of a select:

var status = $("#Status").val();
var status = $("#Status")[0].value;
var status = $('#Status option:selected').val();

How to disable a select?
in both variants, value can be changed using:


User can not interact with the dropdown. And he doesn’t know what other options might exists.

$('#Status').prop('disabled', true);


User can see the options in the dropdown but all of them are disabled:

$('#Status option').attr('disabled', true);

In this case, $("#Status").val() will only work for jQuery versions smaller than 1.9.0. All other variants will work.

How to update a disabled select?

From code behind you can still update the value in your select. It is disabled only for users:


In some cases you might need to fire events:


you should use this syntax:

var value = $('#Id :selected').val();

So try this Code:

var values = $('#aioConceptName :selected').val();

you can test in Fiddle: http://jsfiddle.net/PJT6r/9/

see about this answer in this post

to find correct selections with jQuery consider multiple selections can be available in html trees and confuse your expected output.

(:selected).val() or (:selected).text() will not work correct on multiple select options. So we keep an array of all selections first like .map() could do and then return the desired argument or text.

The following example illustrates those problems and offers a better approach

<select id="form-s" multiple="multiple">
    <option selected>city1</option>
    <option selected value="c2">city2</option>
    <option value="c3">city3</option>
<select id="aioConceptName">
    <option value="s1" selected >choose io</option>
    <option value="s2">roma </option>
    <option value="s3">totti</option>
<select id="test">
    <option value="s4">paloma</option>
    <option value="s5" selected >foo</option>
    <option value="s6">bar</option>
$('select').change(function() {
    var a=$(':selected').text(); // "city1city2choose iofoo"
    var b=$(':selected').val();  // "city1" - selects just first query !
    var c=$(':selected').map(function(){ // ["city1","city2","choose io","foo"]
        return $(this).text();
    var d=$(':selected').map(function(){ // ["city1","c2","s1","s5"]
        return $(this).val();

see the different bug prone output in variant a, b compared to correctly working c & d that keep all selections in an array and then return what you look for.

Just this should work:

var conceptName = $('#aioConceptName').val();

$(function() {
  $('#aioConceptName').on('change', function(event) {
    console.log(event.type + " event with:", $(this).val());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="name" />
<select id="aioConceptName">
  <option>choose io</option>

Using jQuery, just add a change event and get selected value or text within that handler.

If you need selected text, please use this code:

$("#aioConceptName").change(function () {
    alert($("#aioConceptName :selected").text())

Or if you need selected value, please use this code:

$("#aioConceptName").change(function () {
    alert($("#aioConceptName :selected").attr('value'))

For anyone who found out that best answer don’t work.

Try to use:

  $( "#aioConceptName option:selected" ).attr("value");

Works for me in recent projects so it is worth to look on it.

Use the jQuery.val() function for select elements, too:

The .val() method is primarily used to get the values of form elements
such as input, select and textarea. In the case of select elements, it
returns null when no option is selected and an array containing the
value of each selected option when there is at least one and it is
possible to select more because the multiple attribute is present.

$(function() {
  $("#aioConceptName").on("change", function() {
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<select id="aioConceptName">
  <option>choose io</option>
<div id="debug"></div>

Straight forward and pretty easy:

Your dropdown

<select id="aioConceptName">
    <option>choose io</option>

Jquery code to get the selected value

$('#aioConceptName').change(function() {
    var $option = $(this).find('option:selected');

    //Added with the EDIT
    var value = $option.val(); //returns the value of the selected option.
    var text = $option.text(); //returns the text of the selected option.

For get value of tag selected:


And if you want to get text use this code:


For Example:

<div id="i_am_parent_of_select_tag">
        <option value="1">CR7</option>
        <option value="2">MESSI</option>

 $('#i_am_parent_of_select_tag').find(":selected").val();//OUTPUT:1 OR 2
 $('#i_am_parent_of_select_tag').find(":selected").text();//OUTPUT:CR7 OR MESSI

You can try to debug it this way:

console.log($('#aioConceptName option:selected').val())

I hope this also helps to understand better and helps
try this below,

$('select[id="aioConceptName[]"] option:selected').each(function(key,value){
   options2[$(this).val()] = $(this).text();

to more details please

If you want to grab the ‘value’ attribute instead of the text node, this will work for you:

var conceptName = $('#aioConceptName').find(":selected").attr('value');

Here is the simple solution for this issue.

$("select#aioConceptName").change(function () {
           var selectedaioConceptName = $('#aioConceptName').find(":selected").val();;

try to this one

$(document).ready(function() {

    $("#name option").filter(function() {
        return $(this).val() == $("#firstname").val();
    }).attr('selected', true);

    $("#name").live("change", function() {


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<select id="name" name="name"> 
<option value="">Please select...</option> 
<option value="Elvis">Elvis</option> 
<option value="Frank">Frank</option> 
<option value="Jim">Jim</option> 

<input type="text" id="firstname" name="firstname" value="Elvis" readonly="readonly">

$('nameofDropDownList').prop('selectedIndex', whateverNumberasInt);

Imagine the DDL as an array with indexes, you are selecting one index. Choose the one which you want to set it to with your JS.

You can use $("#drpList").val();

to fetch a select with same class= name you could do this, to check if a select option is selected.

var bOK = true;
    if($(el).find(":selected").text() == "") {
        bOK = false;

I had the same issue and I figured out why it was not working on my case
The html page was divided into different html fragments and I found that I have another input field that carries the same Id of the select, which caused the val() to be always empty
I hope this saves the day for anyone who have similar issue.



There is only one correct way to find selected option – by option value attribute. So take the simple code:

//find selected option
$select = $("#mySelect");
$selectedOption = $select.find( "option[value=" + $select.val() + "]" );
//get selected option text
console.log( $selectedOption.text() );

So if you have list like this:

<select id="#mySelect" >
  <option value="value1" >First option</option>
  <option value="value2" >Second option</option>
  <option value="value3" selected >Third option</option>

If you use selected attribute for option, then find(":selected") will give incorrect result because selected attribute will stay at option forever, even user selects another option.

Even if user will selects first or second option, the result of $(“select option:selected”) will give two elements! So $(“select :selected”).text() will give a result like “First option Third option

So use value attribute selector and don’t forget to set value attribute for all options!

Leave a Reply

Your email address will not be published. Required fields are marked *