Here I will explain how to get asp.net textbox in JavaScript or get asp.net label value in JavaScript or get asp.net control values textbox, label etc in JavaScript.
Description:
In previous articles I explained jQuery display testimonials with CSS example, jQuery get or access session value, jQuery right click context menu example, jQuery Add text to end of div and many articles relating to JQuery, JavaScript, asp.net, code snippets. Now I will explain how to get asp.net textbox or label value in JavaScript.
Get Asp.net Textbox or 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 amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML Get label value var name = document.getElementById("<%=txtUserName.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 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> |
Live Demo
To test live example click on below button
|
No comments:
Post a Comment