Get Dropdown Selected Value using JavaScript

We will see how to Get Dropdown selected Value using javascript..?

First create javascript function as GetMaster1Details:

  1. function GetMaster1Details()

  2.  
  3.    var value = document.getElementById("<%=ddlMaster1.ClientID%>");  
  4.    var getvalue = value.options[value.selectedIndex].value;  
  5.    var gettext = value.options[value.selectedIndex].text;  
  6.    alert("value:-" +" "+ getvalue + " ""Text:-" +" "+ gettext);  
  7. }  
Then use this function to dropdown on onchange event as:
  1. <asp:DropDownList ID="ddlMaster1" runat="server" onchange="GetMaster1Details()">  
  2. </asp:DropDownList>  
And See output is:

output

Ebook Download
View all
Learn
View all