Showing posts with label DropDownList get selected Text. Show all posts
Showing posts with label DropDownList get selected Text. Show all posts

Friday, March 10, 2017

asp.net DropDownList get selected Text and Value

You can use JavaScript or jQuery to get the selected text/value of a fiven dropdownl list as shown below.

HTML
<asp:DropDownList ID="ddlPerson" runat="server"  onchange="GetSelected(this)">
                                                                           

JavaScript

<script type="text/javascript">

    function GetSelectedTextValue(ddl) {
        var selectedText = ddl.options[ddl.selectedIndex].innerHTML;
        var selectedValue = ddl.value;
        alert("Text: " + selectedText + " Value: " + selectedValue);
    }

</script>

jQuery

 <script type="text/javascript">

    $(function () {
        $("#ddlPerson").change(function () {
            var selectedText = $(this).find("option:selected").text();
            var selectedValue = $(this).val();
            alert("Text: " + selectedText + " Value: " + selectedValue);
        });
    });

</script>

Cheers
Samita