user2514925
user2514925

Reputation: 949

Jquery to get the value of Dropdown list

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>

Following code for a button,

  <input type="button" name="Excel" value="ExportToExcel" onclick="javascript:DownloadExcel($('#dropdown').val());" />

Following is the Jquery function,

   function DownloadExcel(value)
{  
debugger;
if(value=="Blocked Details"){
value="1";
}
else if(value=="Supervisor Input"){
value="2";
}
    $.ajax({
    url:"@Url.Action("TravelReadyAdminDownload", "TravelReady")",
    datatype:"html",
    type:"post",
    data:{Id:value},
    error:function(){},
    success:function(data){
    window.location.href=data.url;}     
    });   
} 

is it possible to get the dropdown values("1/2" instead of "Blocked Details/Supervisor Input").What is the javascript i need to use to get the value in that function?

Upvotes: 0

Views: 370

Answers (2)

Praveen
Praveen

Reputation: 56509

Selected dropdown value can be fetched like

$('#dd').val();

or

$('#dd option:selected').val();

EDIT: Actually you're doing it right, following are your mistakes

1) wrong selector

$('#dropdown').val()// WRONG selector

it has to be

onclick="javascript:DownloadExcel($('#ddd').val());" //Correct

2) value parameter will hold only value (1 or 2) not text (Blocked Details or Supervisor Input)

Also following is the right way

if(value=="1"){
    //do something
}
else if(value=="2"){
   //do something
}

Upvotes: 2

user3030436
user3030436

Reputation: 21

Can you try the following $('#dropdown :selected').val()

Upvotes: 1

Related Questions