23 January 2014

To get selected value text of a dropdown list using jQuery in asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="HA.Web.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#id11').change(function () {
                alert($("#id11 option:selected").text());
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="id11" runat="server">
            <asp:ListItem Text="1" Value="1a"></asp:ListItem>
            <asp:ListItem Text="2" Value="2a"></asp:ListItem>
            <asp:ListItem Text="3" Value="3a"></asp:ListItem>
            <asp:ListItem Text="4" Value="4a"></asp:ListItem>
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>


No comments:

Post a Comment