Wednesday, July 17, 2013

capture dropdownlist value in javascript | Example : Fetch or get asp.net dropdownlist control value in javascript

hi in this post i will show how to capture dropdownlist control value in javascript

Code :

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function getValue() {
         
            var ddl = document.getElementById("<%=DropDownList1.ClientID%>");
            var ddlValue = ddl.options[ddl.selectedIndex].value;
            alert(ddlValue);

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value="1">IT</asp:ListItem>
            <asp:ListItem Value="2">Accounts</asp:ListItem>
            <asp:ListItem Value="3">Operations</asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get DropDown Selected Value" OnClientClick="return getValue();" />
    </div>
    </form>
</body>
</html>

Result:



No comments:

Post a Comment