Question
How to Get the Selected Option from a Dropdown in jQuery
Question
I usually use $("#id").val() to return the value of the selected option, but in this case it does not seem to work.
The <select> element has the id aioConceptName.
<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>
<option>roma</option>
<option>totti</option>
</select>
How can I correctly get the selected option from this dropdown using jQuery?
Short Answer
By the end of this page, you will understand how jQuery reads values from <select> dropdowns, when .val() works, how to get the selected option's text, and how to avoid common mistakes when working with form controls.
Concept
A <select> element lets a user choose one option from a list. In jQuery, the most common way to read the current selection is:
$("#aioConceptName").val()
This returns the value of the currently selected <option>.
If an <option> does not explicitly define a value attribute, the browser uses the option's text as its value. That means this HTML:
<option>roma</option>
behaves similarly to:
<option value="roma">roma</option>
This matters because developers often need one of two things:
- the option's value for processing or saving data
- the option's visible text for display purposes
In real programs, dropdowns are used in forms, filters, dashboards, settings pages, and admin tools. Knowing the difference between value and text helps prevent bugs and makes form handling more predictable.
Mental Model
Think of a dropdown like a labeled set of choices in a vending machine.
- The text is what the user sees on the button.
- The value is the internal code the machine uses.
Sometimes they are the same:
- text:
roma - value:
roma
Sometimes they are different:
- text:
AS Roma - value:
roma
jQuery's .val() gives you the machine's internal code. If you want the visible label, you read the selected option's text instead.
Syntax and Examples
Get the selected value
var selectedValue = $("#aioConceptName").val();
console.log(selectedValue);
If the user selects roma, this prints:
roma
Get the selected text
var selectedText = $("#aioConceptName option:selected").text();
console.log(selectedText);
This also prints the visible text of the selected option.
Better HTML with explicit values
It is often clearer to define value attributes yourself:
<select id="aioConceptName">
<option value="">choose io</option>
<option value=>roma
totti
Step by Step Execution
Consider this example:
<select id="aioConceptName">
<option value="">choose io</option>
<option value="roma">roma</option>
<option value="totti">totti</option>
</select>
var result = $("#aioConceptName").val();
console.log(result);
What happens step by step
- jQuery looks for the element with id
aioConceptName. - It finds the
<select>element. .val()reads the currently selected option.- If the first option is still selected, the result is an empty string
""because its value is empty. - If the user selects , the result becomes .
Real World Use Cases
Dropdown selection is used in many practical cases:
- Form submission: getting a selected country, category, or role
- Filtering data: selecting a product type or status in a dashboard
- Settings pages: choosing a theme, language, or timezone
- Search interfaces: narrowing results by sort order or tag
- Admin panels: selecting users, permissions, or content states
Example: filter a list when a dropdown changes.
$("#statusFilter").on("change", function () {
var status = $(this).val();
console.log("Filtering by:", status);
});
Real Codebase Usage
In real projects, developers usually combine dropdown reading with validation and event handling.
Common patterns
Guard clause for placeholder options
var value = $("#aioConceptName").val();
if (!value) {
console.log("Please choose an option.");
return;
}
This avoids processing an empty placeholder value.
Reading text and value separately
var value = $("#aioConceptName").val();
var text = $("#aioConceptName option:selected").text();
Useful when you store the value but display the label.
Change-driven UI updates
$("#aioConceptName").on("change", function () {
var selected = $(this).val();
$("#output").text("Selected: " + selected);
});
Common Mistakes
1. Expecting text when .val() returns value
If your option has different text and value:
<option value="roma">AS Roma</option>
then this:
$("#aioConceptName").val()
returns:
"roma"
not AS Roma.
Use this for text:
$("#aioConceptName option:selected").text()
2. Forgetting to add value attributes
This is valid:
<option>roma</option>
but it can be less explicit. Prefer:
Comparisons
| Task | jQuery code | What it returns |
|---|---|---|
| Get selected value | $("#aioConceptName").val() | The selected option's value |
| Get selected text | $("#aioConceptName option:selected").text() | The visible text of the selected option |
| Listen for changes | $("#aioConceptName").on("change", fn) | Runs code when selection changes |
.val() vs .text()
| Method | Use when | Example result |
|---|---|---|
.val() |
Cheat Sheet
Quick reference
Get selected value
$("#aioConceptName").val()
Get selected text
$("#aioConceptName option:selected").text()
Run code when selection changes
$("#aioConceptName").on("change", function () {
console.log($(this).val());
});
Recommended HTML
<select id="aioConceptName">
<option value="">choose io</option>
<option value="roma">roma</option>
<option value=>totti
FAQ
Why does .val() sometimes seem not to work on a dropdown?
Usually the issue is not .val() itself. Common causes are using the wrong selector, running the code before the element exists, or expecting the visible text instead of the value.
How do I get the selected option text instead of the value in jQuery?
Use:
$("#aioConceptName option:selected").text()
Do <option> elements need a value attribute?
No, but it is strongly recommended. Without it, the browser uses the option text as the value.
What does .val() return if the first placeholder option is selected?
It returns that option's value. If you set value="", it returns an empty string.
How can I detect when the user changes the dropdown?
Use the change event:
$("#aioConceptName").on("change", function () {
console.log($().());
});
Mini Project
Description
Build a small dropdown reader that shows both the selected value and the selected text when the user changes the selection. This demonstrates the difference between an option's internal value and its visible label.
Goal
Create a dropdown that updates the page with the currently selected value and label.
Requirements
- Create a
<select>element with at least three options - Give each option an explicit
valueattribute - Listen for the
changeevent with jQuery - Display both the selected value and selected text on the page
Keep learning
Related questions
Can You Style Half a Character in CSS? Text Effects with CSS and JavaScript
Learn how to style half of a character using CSS and JavaScript, including overlay techniques for dynamic text effects.
Check If a Checkbox Is Checked with jQuery
Learn how to check whether a checkbox is checked in jQuery using the correct selector, with examples, mistakes, and practical patterns.
Convert HTML and CSS to PDF in PHP: Options, Limits, and Practical Approaches
Learn how HTML-to-PDF conversion works in PHP, why CSS support varies, and how to choose a practical approach for Linux web servers.