Reputation: 6918
i want to get the selected value from dropdownlist using jquery or javascript. Please help me
Upvotes: 0
Views: 1561
Reputation: 21191
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.
Upvotes: 0
Reputation: 4659
The simplest way to do this via jquery is give the
<select ID="Whatever">
element an ID then call a function onblur or onsubmit
function whatever() { alert($("#Whatever").val()); }
Upvotes: 0
Reputation: 31033
$(function(){
$("#ddlID").change(function(){
console.log($(this).val());
});
});
here is the fiddle http://jsfiddle.net/ah2Y8/
Upvotes: 1
Reputation: 6918
Try this
<script type="text/javascript">
function getDropDownList1Value()
{
var SelectedVal = $('#< %=<strong>DropDownList1.ClientID %>').val();
return SelectedVal;
}
If you want to get its selected text the try this
$('#drop :selected').text();
Upvotes: 0