Thursday, July 1, 2010

How to get Drop Down List Selected Text in ASP .NET by using jQuery

The Following code sample shows how to get selected text out from ASP .NET Drop Down List.
<script type="text/javascript">

    function GetSelectedText() {
        var ddlID = '#' + '<%= ddlEmployees.ClientID %>';
        var selectedText = $(ddlID + " option:selected").text();
        return selectedText;
    }

</script>

<asp:DropDownList ID="ddlEmployees" runat="server">
    <asp:ListItem Text="Employee Name 1" Value="1"></asp:ListItem>
        <asp:ListItem Text="Employee Name 2" Value="2"></asp:ListItem>
        <asp:ListItem Text="Employee Name 2" Value="2"></asp:ListItem>
</asp:DropDownList>

Source: https://www.nilebits.com/blog/2010/05/how-to-get-dropdownlist-selected-text-in-asp-net-by-using-jquery/