Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
hi,

How to get Value of dropdown list in JQuery

i have the code that


C#
var trial = $("#ddlAM option:selected").text();
            alert(trial);



where ddlAM s my Dropdown List.

Please help me.
Posted
Updated 19-Oct-16 4:26am
v2
Comments
Vincent Maverick Durano 18-Oct-16 14:23pm    
how do you populate your list? Does your list contain any data at all? Could you post your dropdown markup?

To get selected value:
$("#ddl").val();

To get selected text:
$("#ddl option:selected").text();

If you are getting blank values then have a look at the data.
 
Share this answer
 
Comments
anvas kuttan 7-Jun-11 0:20am    
do you have the answer i mean i tried in different ddls too it has data but when i alerting the value it just have a blank message box
see here[^]
 
Share this answer
 
Comments
anvas kuttan 4-Jun-11 3:38am    
hi, thank you for your reply .. i done it but i am getting blank, when alerting the value
Check out this...

<script type="text/javascript">
function getDropDownList1Value()
{
var SelectedVal = $('#< %=<strong>DropDownList1.ClientID %>').val();
return SelectedVal;
}
</script>
 
Share this answer
 
Comments
astrixtech 29-May-13 8:23am    
What if we have to know the different values in the dropdown list?
Use this code to get the selected value of dropdownlist in Jquery, this code will get the selected item text and assign to a hidden text field.

replace .text() with .value() to get the dropdownlist selected value

HTML
<script>
    $(document).ready(function () {
        $("#ddEmployees").change(function () {
            $("#ddSelectedItemText").val($('option:selected', $(this)).text());
        });
    });
</script>
 @Html.DropDownList("ddEmployees", (SelectList)ViewData["Employees"], "---Select---", new {@class="DropDownCssIfAny"})
 
 
<input type='hidden' name='ddSelectedItemText' id='ddSelectedItemText' />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900