how to get drop down selected text in jQuery

Total Post:12

Points:84
JQuery 
 160  View(s)
Ratings:
Rate this:

how to get drop down selected text in jQuery

  1. Post:140

    Points:984
    Re: how to get drop down selected text in jQuery

    Jquery dropdown for text :

    Here is the code for DropDownList control in ASP.NET :

    <asp:DropDownList ID="DropDownList1" runat="server" > 
       <asp:ListItem Value="1">Allahabad</asp:ListItem>
       <asp:ListItem Value="2">Mindstick</asp:ListItem>
       <asp:ListItem Value="3">Software</asp:ListItem>
    </asp:DropDownList>

    Following JQuery code snippet will give you selected choice name from the above DropDownList control.

    Sytax :

    var country = $("#DropDownList1 option:selected").text(); 

    Ex:  In HTML/Jscipt :

    Select color:

    <select id="favcolor">
    
        <option value=""></option>
        <option value="1">Red</option>
        <option value="2">Yellow</option>
        <option value="3">White</option>
    </select>
        <input type="button" id = "btnGet" value="Get Selected Text Value" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnGet").click(function () {
                var selectedText = $("#ddlFruits").find("option:selected").text();
                alert("Selected Text: "selectedText");
            });
        });
    </script>

    Happy Coding  :)

      Modified On Jun-18-2018 10:31:00 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!