All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

jQuery Get Selected Option Value

Last Updated : Mar 11, 2024

jQuery Get Selected Option Value

In this article we will show you the solution of jQuery get selected option value, to locate the selected option value in a pick box or dropdown list, combine the val() function and the jQuery:selected selection.

From pick boxes and dropdowns, jQuery select value enables you to retrieve the value of a selected option.

To do this, jQuery provides two methods: text() and val(). To determine a value for the selected item in a pick box or dropdown, use the jQuery selected selector in conjunction with the val() or text() method.

We may get the value to just be transmitted to the server using the val() function or the textual value of a chosen element using the text() method.

Step By Step Guide On jQuery Get Selected Option Value :-

<!DOCTYPE html>
<title>jQuery Get Selected Option Value</title>
<script src=""></script>
$(document).ready(function () {
$("#SubjectsList").change(function () {
var selectedSubject = $("#SubjectsList option:selected").val();
alert("You have selected the country - " + selectedSubject);
#divstyle {
width: 500px;
height: 250px;
padding-top: 20px;
padding-left: 5px;
font-size: 24px;
text-align: center;
color: maroon;
background-color: cadetblue;
<div id ="divstyle">
<h3>jQuery select value using val() method</h3>
<label style="font-size: 20px;">Select:</label>
<select id="SubjectsList">
<option value="eng">English</option>
<option value="phy">Physics</option>
<option value="chem">Chemistry</option>
<option value="maths">Mathematics</option>
  1. The first step is to write <HTML>, which tells the browser what version of HTML we're using. A tag is the first element of an HTML document.
  2. Use the <head> tag to describe the project's heading. In contrast to the final brackets, which are closed, the title and final brackets both are open.
  3. The <script> tag was then added. The script tag also includes the javascript google API run or an explanation of the code or file we used.
  4. The script is then closed and head closed.
  5. The <body> tag, which describes the webpage's body, is then placed after this. This is where the website's content is written.
  6. Then we create a jquery select value using val() method.
  7. Then again the <script> tag was then added. The script tag also includes the javascript google API run or an explanation of the code or file we used for button variable value.
  8. After that we close </script></div></body></html>

Conclusion :-

I hope this article on jQuery get selected option value helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪