In this article I will explain How to get ASP.NET
Label and TextBox values in JavaScript
Get Asp.net Textbox And Label Value in JavaScript
To
get ASP.NET textbox or label value in JavaScript we need to write a code like
as shown below
Get label value
var Name = document.getElementById("<%=lblName.ClientID %>").innerHTML
Get label value
var LastName =
document.getElementById("<%=txtLastName.ClientID
%>").value;
If you want to see it in complete example check below code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Get Asp.net Textbox Value in JavaScript</title>
<script type="text/javascript">
function getvalues() {
var LastName =
document.getElementById("<%=txtLastName.ClientID
%>").value;
var Name = document.getElementById("<%=lblName.ClientID %>").innerHTML;
alert("Textbox Value: "+name+"\n" +"Label
Value: "+ amount);
return false
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
UserName:<asp:TextBox ID=" lblName " runat="server" /><br />
LastName:<asp:Label ID=" txtLastName " runat="server" Text="10000"/><br />
<asp:Button ID="btnValidate" runat="server" Text="Get Values" OnClientClick="javascript:getvalues();" />
</div>
</form>
</body>
</html>
No comments:
Post a Comment