Learn how to get the value of a select option using jQuery

jquery-theonlytutorials

 

This post explains you how to get the value of the selected option from the select box using jQuery.

Its pretty simple in jQuery, Look at the below syntax:


$('#yourselectboxid :selected').val()

the above one line of code will give you the selected value.

For your convenience i have written a demo snippet below:


<html>
<head>
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function(){
$('#selectnumber').change(function(){
alert($('#selectnumber :selected').val());
});
})
</script>
</head>
<body>
<select id="selectnumber">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
</body>

Copy and paste the above script and test it yourself!

Also Click here to see how to get the text of a select option using jquery

One thought on “Learn how to get the value of a select option using jQuery

Leave a Reply

Theme: Overlay by Kaira
Agurchand