HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptCritical

jQuery Get Selected Option From Dropdown

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
fromjqueryoptionselectedgetdropdown

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

Name

AIO Concept Name

    choose io
    roma
    totti

Solution

For dropdown options you probably want something like this:

For selected text

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


For selected value

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


The reason val() doesn't do the trick is because clicking an option doesn't change the value of the dropdown--it just adds the :selected property to the selected option which is a child of the dropdown.

Code Snippets

var conceptName = $('#aioConceptName').find(":selected").text();
var conceptName = $('#aioConceptName').find(":selected").val();

Context

Stack Overflow Q#10659097, score: 2366

Revisions (0)

No revisions yet.