Saturday, 29 October 2016

jQuery - How to get selected text of dropdownlist


Watch this example on YouTube:


<head runat="server">
    <title></title>
   
    <script  type="text/javascript" src="Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('.rb').click(function () {
                alert($("#DropDownList1").find("option:selected").text());
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>ONE</asp:ListItem>
            <asp:ListItem>TWO</asp:ListItem>
            <asp:ListItem>THREE</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="Button1" class="rb" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment