HTML Markup
<asp:DropDownList ID="ddlFruits" runat="server" onchange="OnDropDownChanged(this)">
<asp:ListItem Text="Please select" Value=""></asp:ListItem>
<asp:ListItem Text="Mango" Value="1"></asp:ListItem>
<asp:ListItem Text="Apple" Value="2"></asp:ListItem>
<asp:ListItem Text="Banana" Value="3"></asp:ListItem>
</asp:DropDownList>
Client Side OnChange event JavaScript implementation
The Text part of the selected Item is fetched using innerHTML while the Value part is determined using the Value property.
Finally, the Text and Value are displayed in
JavaScript Alert Message Box.
<script type="text/javascript">
function OnDropDownChanged(ddlFruits) {
var selectedText = ddlFruits.options[ddlFruits.selectedIndex].innerHTML;
var selectedValue = ddlFruits.value;
alert("Selected Text: " + selectedText + " Value: " + selectedValue);
};
</script>
Screenshot
Demo
Downloads