JS to get the value of the DropDownList and the value of the text sample code

  • 2020-03-30 01:15:48
  • OfStack

Relevant JS:

<script type="text/javascript" language="javascript">
    function SearchChange()
    {
        var ddl = document.getElementById("DropDownList1")   
        var index = ddl.selectedIndex;   

        var Value = ddl.options[index].value;   
        var Text = ddl.options[index].text;

        alert(Value);
    }
    </script>

Call:

<asp:DropDownList ID="DropDownList1" runat="server" onchange="SearchChange();">
    <asp:ListItem Value="0">111</asp:ListItem>
    <asp:ListItem Value="1">222</asp:ListItem>
    <asp:ListItem Value="2">333</asp:ListItem>
</asp:DropDownList

Related articles: