0

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?

1
  • `$("#dd option:selected").val() will do. Commented Nov 25, 2013 at 7:38

2 Answers 2

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

This does the same as $('#dropdown').val(), but slows down the selector unnecessarily. See api.jquery.com/val

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.