2014年4月2日 星期三

JavaScript Get Asp.net Textbox Value | Get Asp.net Label Value in JavaScript

http://www.aspdotnet-suresh.com/2013/10/javascript-get-aspnet-textbox-value-label-value.html

Get label value

var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML

Get label value

var name = document.getElementById("<%=txtUserName.ClientID %>").value;


<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 name = document.getElementById("<%=txtUserName.ClientID %>").value;
var amount = document.getElementById("<%=lblAmount.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="txtUserName" runat="server" /><br />
Amount:<asp:Label ID="lblAmount" runat="server" Text="10000"/><br />
<asp:Button ID="btnValidate" runat="server" Text="Get Values" OnClientClick="javascript:getvalues();" />
</div>
</form>
</body>
</html>

沒有留言:

張貼留言