Question
How to Get Selected Text from a Select Box in jQuery
Question
How can I get the selected text, rather than the selected value, from a drop-down list (select box) using jQuery?
Short Answer
By the end of this page, you will understand how to read the visible text of the currently selected <option> in a jQuery <select> element. You will also learn the difference between option text and option value, how to react to selection changes, and how this pattern is used in real projects.
Concept
In HTML, a drop-down list is usually created with a <select> element that contains one or more <option> elements.
Each <option> can have:
- a value: the data sent or stored internally
- a text label: the human-readable text shown to the user
For example:
<select id="country">
<option value="us">United States</option>
<option value="ca">Canada</option>
</select>
Here:
usandcaare the valuesUnited StatesandCanadaare the visible text labels
In jQuery, beginners often use .val() first. That works when you want the selected value, but not when you want the displayed text.
To get the selected text, you target the selected <option> and then read its text:
$('#country option:selected').text()
This matters because real applications often need both:
- the value for saving to a database or sending to an API
- the text for display in messages, summaries, or previews
Understanding this difference helps you avoid bugs like showing us to a user when you meant to show United States.
Mental Model
Think of a <select> like a menu in a restaurant:
- the value is the kitchen's internal item code
- the text is the name printed on the menu
A user sees "Canada", but your code might store "ca".
If you ask for .val(), you get the internal code.
If you ask for the selected option's .text(), you get what the user actually sees.
Syntax and Examples
The basic jQuery syntax is:
$('#mySelect option:selected').text()
Example HTML
<select id="fruit">
<option value="ap">Apple</option>
<option value="ba">Banana</option>
<option value="or">Orange</option>
</select>
Get the selected text
var selectedText = $('#fruit option:selected').text();
console.log(selectedText);
If Banana is selected, the result is:
Banana
Compare with selected value
var selectedValue = $('#fruit').val();
var selectedText = $('#fruit option:selected').text();
console.log(selectedValue); // ba
console.log(selectedText); // Banana
React when the user changes the selection
$('#fruit').change(function () {
var text = $('#fruit option:selected').text();
console.log('You selected: ' + text);
});
This is useful when you want to update the page immediately after the user picks an item.
Step by Step Execution
Consider this example:
<select id="city">
<option value="ny">New York</option>
<option value="ldn">London</option>
<option value="tky">Tokyo</option>
</select>
var selectedText = $('#city option:selected').text();
console.log(selectedText);
Step by step
-
$('#city option:selected')- jQuery finds the element with
id="city". - Inside that
<select>, it looks for the currently selected<option>.
- jQuery finds the element with
-
.text()- jQuery reads the text content of that selected
<option>.
- jQuery reads the text content of that selected
-
var selectedText = ...- The result is stored in the variable
selectedText.
- The result is stored in the variable
-
console.log(selectedText)- The text is printed to the console.
Example trace
If the HTML is currently:
<option value="ldn" selected>London</option>
Then:
- selected option =
London .val()would returnldn.text()returnsLondon
So the console output becomes:
London
Real World Use Cases
Getting selected text is useful in many practical situations:
- Confirmation messages
- Show:
You selected: Canada
- Show:
- Order summaries
- Display the product name the user picked
- Profile settings pages
- Show a readable label instead of an internal code
- Dynamic UI updates
- Update headings, previews, or descriptions based on the selected option
- Form review screens
- Show user-friendly text before final submission
- Reporting and exports
- Use readable labels for generated summaries
Example: update a preview area
$('#fruit').change(function () {
var selectedText = $('#fruit option:selected').text();
$('#preview').text('Selected fruit: ' + selectedText);
});
This keeps the interface readable for users.
Real Codebase Usage
In real projects, developers usually do more than just read the text once.
Common patterns
- Event-driven updates
- Read selected text inside a
.change()handler
- Read selected text inside a
- Guard clauses
- Check whether a valid option is selected before using the text
- Display + submit split
- Use
.val()for backend data and.text()for frontend display
- Use
- Form validation
- Ignore placeholder options such as
Select one
- Ignore placeholder options such as
- Reusable helpers
- Wrap the logic in a small function for repeated use
Example with a guard clause
$('#country').change(function () {
var value = $(this).val();
var text = $(this).find('option:selected').text();
if (!value) {
$('#message').text('Please choose a country.');
return;
}
$('#message').text('Selected country: ' + text);
});
Reusable helper example
function getSelectedText(selector) {
return $(selector).find('option:selected').text();
}
var text = getSelectedText('#country');
console.log(text);
This approach makes code easier to reuse and maintain.
Common Mistakes
1. Using .val() when you need visible text
Broken example:
var text = $('#fruit').val();
console.log(text);
This returns the option's value, not its label.
Correct version:
var text = $('#fruit option:selected').text();
2. Forgetting to target the selected option
Broken example:
var text = $('#fruit option').text();
This may return the combined text of all options.
Correct version:
var text = $('#fruit option:selected').text();
3. Using the wrong selector inside an event handler
Less ideal:
$('#fruit').change(function () {
var text = $('#fruit option:selected').text();
});
Better:
$('#fruit').change(function () {
var text = $(this).find('option:selected').text();
});
Using $(this) is cleaner and works better if multiple selects use the same handler.
4. Not handling placeholder options
Example:
<select id="country">
<option value="">Select a country</option>
<option value="us">United States</option>
</select>
If the first option is selected, .text() returns Select a country.
Avoid mistakes by checking the value too:
var value = $('#country').val();
var text = $('#country option:selected').text();
if (!value) {
console.log('No real selection yet');
}
5. Assuming text and value are always different
Sometimes they are the same:
<option value="Apple">Apple</option>
In that case, .val() and .text() produce the same result. But do not rely on that unless your HTML is designed that way.
Comparisons
| Goal | jQuery code | Result |
|---|---|---|
| Get selected value | $('#fruit').val() | Returns the selected option's value |
| Get selected text | $('#fruit option:selected').text() | Returns the visible label |
| Get selected option element | $('#fruit option:selected') | Returns the selected <option> as a jQuery object |
.val() vs .text()
| Method | Used on | Returns | Common use |
|---|---|---|---|
.val() | <select> or form field | Internal value | Submission, filtering, IDs, codes |
.text() | Selected <option> | Visible text | Display, messages, summaries |
Two common ways to get selected text
$('#fruit option:selected').text()
$('#fruit').find('option:selected').text()
These are effectively equivalent. The second version is often easier to reuse inside event handlers:
$('#fruit').change(function () {
var text = $(this).find('option:selected').text();
});
Cheat Sheet
Get selected text
$('#mySelect option:selected').text()
Get selected value
$('#mySelect').val()
Best pattern inside change()
$('#mySelect').change(function () {
var value = $(this).val();
var text = $(this).find('option:selected').text();
});
Key rule
- Use
.val()for the option'svalue - Use
.text()for the visible label
Common selector
option:selected
Placeholder edge case
If the selected option is:
<option value="">Select one</option>
Then:
.val()returns"".text()returns"Select one"
Reusable helper
function getSelectedText(selector) {
return $(selector).find('option:selected').text();
}
FAQ
How do I get the selected text of a dropdown in jQuery?
Use:
$('#mySelect option:selected').text()
What is the difference between .val() and .text() in a select box?
.val()returns the selected option'svalue.text()returns the visible text label
Can I get selected text inside a change event?
Yes:
$('#mySelect').change(function () {
var text = $(this).find('option:selected').text();
});
Why does my code return the option value instead of the label?
You are probably using .val(). Use .text() on the selected <option> instead.
Does this work for all select boxes in jQuery?
Yes, as long as the element is a normal HTML <select> and you select the current <option> correctly.
What happens if no real option is selected?
If a placeholder option is selected, .text() returns the placeholder text. Check .val() as well if you need to detect an empty selection.
Mini Project
Description
Build a small country selector that shows both the selected country code and the user-friendly country name. This demonstrates the difference between a select option's value and its visible text, which is a very common pattern in forms.
Goal
Create a dropdown that updates a message showing the selected country's text and value whenever the selection changes.
Requirements
[ "Create a select box with at least three country options", "Include a placeholder option at the top", "Display the selected text and selected value below the dropdown", "Update the display whenever the user changes the selection" ]
Keep learning
Related questions
Abort Ajax Requests with jQuery jqXHR.abort()
Learn how to cancel an in-progress jQuery Ajax request with jqXHR.abort(), handle abort status safely, and avoid stale UI updates.
Access the Correct this Inside a JavaScript Callback
Learn why JavaScript this changes in callbacks and how to preserve an object context using bind, arrow functions, and event handler patterns.
Add Key-Value Pairs to JavaScript Objects
Learn how to add key-value pairs to JavaScript objects with dot and bracket notation, dynamic keys, examples, and common mistakes.