- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 can I get the selected value of a drop-down list with jQuery?
With jQuery, it’s easy to get selected text from a drop-down list. This is done using the select id. To change the selected value of a drop-down list, use the val() method.
Example
You can try to run the following code to learn how to change the selected value of a drop-down list. Here, we have a default select option first, but the alert shows the second option, which have been changed using the val method():
<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() { $("#button1").click(function(){ $("#myselection").val('2'); 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> <option value="3">Third</option> </select> </div> <button id="button1">Click</button> </body> </html>
- Related Articles
- How to get selected text from a drop-down list (select box) using jQuery?
- How to select a drop-down menu option value with Selenium (Python)?
- How to define a drop-down list in HTML5?
- How to Auto-Display a Default Value while Deleting a Value in a Drop-Down List in Excel?
- How can I know which radio button is selected via jQuery?
- How can I know which radio button is selected via jQuery?
- How to get all options in a drop-down list by Selenium WebDriver using C#?
- How to add color to a drop-down list in Excel?
- How to select value from a drop down using Selenium IDE?
- Use jQuery to get values of selected checkboxes?
- How can I get the ID of an DOM element using jQuery?
- How to include an option in a drop-down list in HTML?
- How can I get elements from a Java List?
- How to select/get drop down option in Selenium 2?
- How do we use a simple drop-down list of items in HTML forms?

Advertisements