How to get selected text from a drop-down list (select box) using jQuery?


With jQuery, it’s easy to get selected text from a drop-down list with :selected. This is done using the select id. You can try to run the following code to learn how to get selected text from a drop-down list using jQuery −

Example

Live Demo

<html>
   <head>
      <title>jQuery Selector</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         $(document).ready(function() {
            $("#submit").click(function(){      
               $("#myselection option:selected").text();
               alert( $("#myselection option:selected").text() );
            });
         });
      </script>
   </head>
   <body>
      <div>
         <p>The selected value:</p>
        <select id="myselection">
          <option value="1">First</option>
          <option value="2">Second</option>
        </select>
        <button id="submit">Result</button>
      </div>
   </body>
</html>    

Updated on: 12-Jun-2020

804 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements