0

i want to get the selected value from dropdownlist using jquery or javascript. Please help me

1
  • 1
    What technology are you using (i.e. PHP, ASP.NET, ASP.NET MVC, etc.) to generate the markup? Commented Sep 13, 2011 at 5:43

4 Answers 4

1
$(function(){
$("#ddlID").change(function(){
console.log($(this).val());
});

});

here is the fiddle http://jsfiddle.net/ah2Y8/

Sign up to request clarification or add additional context in comments.

3 Comments

Pretty sure this fails in ASP.NET WebForms.
if he sets the client id mode then the id can be predicted or he can use the class insted of id
Fair enough. Might be worth mentioning that in your answer. :]
0

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();

Comments

0

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()); }

Comments

0

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.

Comments

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.