i want to get the selected value from dropdownlist using jquery or javascript. Please help me
4 Answers
$(function(){
$("#ddlID").change(function(){
console.log($(this).val());
});
});
here is the fiddle http://jsfiddle.net/ah2Y8/
The normal .val() method will get you the selected value of the dropdown, and the .text() method will get you the selected text. The problem you will run into with ASP.NET using WebForms is that the server tags, when generated, contain long concatenated IDs that don't match the ID you specify in the markup. So, your selectors have to be tweaked as @raman shows you above: inject the client ID into the jQuery selector using a server tag. Then the selector will function as normal:
// if you're going to reference it a bunch of times, create an object reference
var $ddl = $('#<%= DropDownList1.ClientID %>');
var selectedvalue = $ddl.val();
var selectedtext = $ddl.text();
HTH.