Hi *.*,
Getting Selected Index and value from asp dropdownlist control through JavaScript.
Core Code
drpCountryList : Dropdown Name
var e = document.getElementById("drpCountryList");
//get the value of the dropDownList
var CountryValue = e.options[e.selectedIndex].value;
//get the Text of the dropDownList
var CoyntryTxt = e.options[e.selectedIndex].text;
Full Code
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function drp() {
// debugger;
var e = document.getElementById("drpCountryList");
//get the value of the dropDownList
var CountryValue = e.options[e.selectedIndex].value;
//get the Text of the dropDownList
var CoyntryTxt = e.options[e.selectedIndex].text;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="drpCountryList" runat="server" onblur="javascript:drp();">
<asp:ListItem Text="India" Value="1"></asp:ListItem>
<asp:ListItem Text="Pakistan" Value="2"></asp:ListItem>
<asp:ListItem Text="China" Value="3"></asp:ListItem>
<asp:ListItem Text="USA" Value="4"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
Have a nice day... 'N happy Coding :)
No comments:
Post a Comment