{"id":1732,"date":"2017-07-01T12:33:16","date_gmt":"2017-07-01T07:03:16","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1732"},"modified":"2026-08-31T17:21:45","modified_gmt":"2026-08-31T11:51:45","slug":"selected-text-drop-list-select-box-using-jquery","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/selected-text-drop-list-select-box-using-jquery\/","title":{"rendered":"How to Get Selected Text and Value from a Drop-Down List Using jQuery"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">HTML <code>&lt;select&gt;<\/code> elements are commonly used to display a list of options from which users can select a value. In many web applications, you may need to retrieve both the <strong>selected option&#8217;s text<\/strong> and its <strong>value<\/strong> using JavaScript or jQuery.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a dropdown may display <code>Basic Plan<\/code> to the user while its underlying value is <code>601<\/code>. jQuery provides simple methods to retrieve both pieces of information from the selected option.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will show how to get the selected text and value from a drop-down list using jQuery.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before following this guide, you should have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basic knowledge of HTML.<\/li>\n\n\n\n<li>Basic knowledge of JavaScript and jQuery.<\/li>\n\n\n\n<li>A web browser for testing the example.<\/li>\n\n\n\n<li>jQuery included in your HTML page.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can use a current jQuery release from the official jQuery CDN:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;script src=\"https:\/\/code.jquery.com\/jquery-3.7.1.min.js\">&lt;\/script><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the HTML Drop-Down List<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a <code>&lt;select&gt;<\/code> element with multiple options:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;select name=\"select_text\" id=\"select_text\">\n    &lt;option value=\"\">Select Plan&lt;\/option>\n    &lt;option value=\"601\">Basic Plan&lt;\/option>\n    &lt;option value=\"602\">Premium Plan&lt;\/option>\n&lt;\/select>\n\n&lt;button type=\"button\" id=\"get-text\">Get Selected Value&lt;\/button><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>value<\/code> attribute contains the value associated with each option, while the text between the <code>&lt;option&gt;<\/code> tags is displayed to the user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;option value=\"601\">Basic Plan&lt;\/option><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Selected text:<\/strong> <code>Basic Plan<\/code><\/li>\n\n\n\n<li><strong>Selected value:<\/strong> <code>601<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Get the Selected Text<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the jQuery <code>:selected<\/code> selector together with <code>.text()<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const selectedText = $(\"#select_text option:selected\").text();\n\nalert(\"Text: \" + selectedText);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns the text displayed by the selected option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Get the Selected Value<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To retrieve the value of the selected option, use <code>.val()<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const selectedValue = $(\"#select_text\").val();\n\nalert(\"Value: \" + selectedValue);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Get Both Text and Value<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The following example retrieves both the selected text and value when the button is clicked:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    &lt;title>Get Selected Text and Value Using jQuery&lt;\/title>\n\n    &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.7.1.min.js\">&lt;\/script>\n&lt;\/head>\n&lt;body>\n\n&lt;select name=\"select_text\" id=\"select_text\">\n    &lt;option value=\"\">Select Plan&lt;\/option>\n    &lt;option value=\"601\">Basic Plan&lt;\/option>\n    &lt;option value=\"602\">Premium Plan&lt;\/option>\n&lt;\/select>\n\n&lt;button type=\"button\" id=\"get-text\">Get Selected Value&lt;\/button>\n\n&lt;script>\n$(function () {\n    $(\"#get-text\").on(\"click\", function () {\n        const selectedText = $(\"#select_text option:selected\").text();\n        const selectedValue = $(\"#select_text\").val();\n\n        alert(\"Text: \" + selectedText);\n        alert(\"Value: \" + selectedValue);\n    });\n});\n&lt;\/script>\n\n&lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When <strong>Basic Plan<\/strong> is selected, the result will be:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Text: Basic Plan\nValue: 601<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Get the Selected Option on Change<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to retrieve the selected text and value immediately whenever the user changes the dropdown, use the <code>change<\/code> event:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(\"#select_text\").on(\"change\", function () {\n    const selectedText = $(this).find(\"option:selected\").text();\n    const selectedValue = $(this).val();\n\n    console.log(\"Text:\", selectedText);\n    console.log(\"Value:\", selectedValue);\n});<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This approach is useful when the application needs to perform an action immediately after the user selects an option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">jQuery provides a simple way to retrieve both the displayed text and the underlying value of a selected drop-down option.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To get the selected text:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(\"#select_text option:selected\").text();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To get the selected value:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(\"#select_text\").val();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These methods can be used with button clicks, change events, forms, and other interactive web application functionality.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. How do I get the selected text from a dropdown using jQuery?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(\"#select_text option:selected\").text();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns the text displayed for the currently selected option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. How do I get the selected value from a dropdown using jQuery?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(\"#select_text\").val();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns the <code>value<\/code> attribute of the selected option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Article <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/check-uncheck-checkbox-using-jquery\/\"><br>How to Check or Uncheck a Checkbox with jQuery<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Talk to our experts:<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Our DevOps experts can help with cloud infrastructure, server management, automation, and other DevOps requirements. Get in touch with our team&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction HTML &lt;select&gt; elements are commonly used to display a list of options from which users can select a value. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-1732","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-rW","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1732"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1732\/revisions"}],"predecessor-version":[{"id":11212,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1732\/revisions\/11212"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}