0

I have used jquery, when I click on the dropdown it will take the value and will search related to the input. But it is not taking the value correctly. If I click on one value it is taking the next value.

<%= Html.DropDownList("Roles", ViewData["Roles"] as SelectList,"Select" , new {onchange = "javascript:ddlRoleChanged();", id="ddlRoles",  @class = "dropdownStyle2"})%>

This is my dropdown. I am taking the id and pass into jquery like the following,

function ddlRoleChanged() {debugger;
     var selectedValue = $('#ddlRoles').val();
     window.location = '/home/homepage?variable=' + selectedValue.valueOf();
 };   

selectedvalue is taking the value. But it is not coming correctly. Please help me.

Duk
  • 905
  • 5
  • 15
  • 34
  • Please add the generated HTML markup – Péter Mar 24 '14 at 05:33
  • If you have a specific problem please explain it properly. *"But it is not coming correctly"* is not a useful problem description. – Felix Kling Mar 24 '14 at 06:18
  • @ChrisMoschini my question is different from another one.. it is not duplicate one. – Duk Mar 24 '14 at 08:50
  • @Duk You appear to be asking how to get the selected value in a – Chris Moschini Mar 25 '14 at 03:28
  • @ChrisMoschini yes you are correct. How do i know if already some people asked.. I want this requirement, so i put this question. any way i ll ask different question if already exists. – Duk Mar 25 '14 at 05:37
  • @Duk When you start typing your question this site shows you similar questions - if one of them is the same thing, stop typing your question and enjoy the fact it's already been answered and off ya go. – Chris Moschini Mar 25 '14 at 06:10

3 Answers3

1
 var selectedValue = $('#ddlRoles').val();

will give you the selected value of the drop down element. Use this to get the selected options text.

$('#ur dropdown id:selected').text();
Abhishek
  • 517
  • 3
  • 18
0

try this way

function ddlRoleChanged() {debugger;
  var selectedValue = $('#ddlRoles option:selected').val();
  window.location = '/home/homepage?variable=' + selectedValue.valueOf();
};   
dreamweiver
  • 6,002
  • 2
  • 24
  • 39
0
$(function(){
    $('#ddlRoles').change(function(){
         var selectedValue = $(this).val();
         location.href = '/home/homepage?variable=' + selectedValue ;
    });
});

try this

Ravinder Gujiri
  • 1,494
  • 10
  • 14