Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
<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> Advertisements