user2514925
user2514925

Reputation: 949

Jquery to get the value of selected dropdown option

I'm using following html for dropdownlist,

   <select id="dd">
   <option>Select ReportType</option>
   <option value="1">Blocked Details</option>
   <option value="2">Supervisor Input</option>
   </select> 

i want to get the option value(1/2) in a variable while changing the option. if i use the following code,

   var value = $('#dd :selected').val();

i'm getting "Blocked Details/Supervisor" Input in the variable i want to get "1/2"

what is the jquery to get it?

Upvotes: 1

Views: 1795

Answers (3)

Sridhar R
Sridhar R

Reputation: 20418

Try this

$('#dd').on('change', function() {
        var id= this.value; 
        alert(id);
});

OR

var value = $('#dd').val();
var value = $('#dd :selected').val();//this also works

Upvotes: 0

Bhadra
Bhadra

Reputation: 2104

$('#dd').change(function(){
      alert($(this).val())
 });

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

just use the select element

var value = $('#dd').val();

Demo: Fiddle

Upvotes: 2

Related Questions