// JavaScript Code
//Diplay the Text and Value of ASP Dropdown List
function DisplayTextAndValueofDropDown() {
var ddlDropDownID = document.getElementById("<%=DropDownList1.ClientID%>");
var DisplayText = ddlDropDownID.options[ddlDropDownID.selectedIndex].text;
var DisplayValue = ddlDropDownID.options[ddlDropDownID.selectedIndex].value;
alert(DisplayText);
alert(DisplayValue);
}
//HTML Code
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem text="TestText" value="TestValue"></asp:listitem>
<asp:listitem text="TempText" value="TempValue"></asp:listitem>
</asp:dropdownlist>
<asp:button id="btnValidation" onclientclick="DisplayTextAndValueofDropDown();" runat="server" text="Click Me"></asp:button>
<asp:listitem text="TestText" value="TestValue"></asp:listitem>
<asp:listitem text="TempText" value="TempValue"></asp:listitem>
</asp:dropdownlist>
<asp:button id="btnValidation" onclientclick="DisplayTextAndValueofDropDown();" runat="server" text="Click Me"></asp:button>
No comments:
Post a Comment