Intoduction :-
Hii Friends...
Today I explain how to get a dropdown list text and value with the help of javascript. The main point is it depends on .text and .value. If you want to get a value of dropdown selected value then you write (.value ) otherwise you write (.Text) .
<head id="Head1" runat="server">
<title>Welcome On Asp.Net Modules</title>
<script type="text/javascript">
function GetCountryDetails() {
var name = document.getElementById("ddlName");
document.getElementById('lbltxt').innerHTML = name.options[name.selectedIndex].text;
document.getElementById('lblid').innerHTML = name.options[name.selectedIndex].value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="50%">
<tr>
<td align="right">
Select Name:
</td>
<td>
<asp:DropDownList ID="ddlName" runat="server" onchange="GetCountryDetails()">
<asp:ListItem Text="Select" Value="0" />
<asp:ListItem Text="Jorge" Value="1" />
<asp:ListItem Text="Herry" Value="2" />
<asp:ListItem Text="Enguju" Value="3" />
<asp:ListItem Text="Yuyu" Value="4" />
<asp:ListItem Text="Gerry" Value="5" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right" style="font-family: Verdana; font-size: 10pt; color: Black">
Selected Text:
</td>
<td>
<b>
<label id="lbltxt" />
</b>
</td>
</tr>
<tr>
<td align="right">
Selected text value:
</td>
<td>
<b>
<label id="lblid" />
</b>
</td>
</tr>
</table>
</form>
</body>
</html>
Hii Friends...
Today I explain how to get a dropdown list text and value with the help of javascript. The main point is it depends on .text and .value. If you want to get a value of dropdown selected value then you write (.value ) otherwise you write (.Text) .
Example :-
<html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">
<title>Welcome On Asp.Net Modules</title>
<script type="text/javascript">
function GetCountryDetails() {
var name = document.getElementById("ddlName");
document.getElementById('lbltxt').innerHTML = name.options[name.selectedIndex].text;
document.getElementById('lblid').innerHTML = name.options[name.selectedIndex].value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="50%">
<tr>
<td align="right">
Select Name:
</td>
<td>
<asp:DropDownList ID="ddlName" runat="server" onchange="GetCountryDetails()">
<asp:ListItem Text="Select" Value="0" />
<asp:ListItem Text="Jorge" Value="1" />
<asp:ListItem Text="Herry" Value="2" />
<asp:ListItem Text="Enguju" Value="3" />
<asp:ListItem Text="Yuyu" Value="4" />
<asp:ListItem Text="Gerry" Value="5" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right" style="font-family: Verdana; font-size: 10pt; color: Black">
Selected Text:
</td>
<td>
<b>
<label id="lbltxt" />
</b>
</td>
</tr>
<tr>
<td align="right">
Selected text value:
</td>
<td>
<b>
<label id="lblid" />
</b>
</td>
</tr>
</table>
</form>
</body>
</html>
0 comments:
Post a Comment