aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript Get Textbox Value | Get Label Value in JavaScript

Oct 4, 2013

Here I will explain how to get textbox in JavaScript or get label value in JavaScript or get control values textbox, label etc in JavaScript.


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,, code snippets. Now I will explain how to get textbox or label value in JavaScript.

Get Textbox or Label Value in JavaScript

To get 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="">
<head runat="server">
<title>Get 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
<form id="form1" runat="server">
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();" />
Live Demo

To test live example click on below button


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Manoj Kumar said...

Hi Suresh,

Some error in heading pls check,

Get label value

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

Get textbox value

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

ranadheerrannu said...

@manoj kumar: nice. He used "label" again instead of "textbox".

Articles Growing Knowledge said...

its not working in Master's Content pages Why

Vakeel Mansoori said...

@manoj Kumar :put a semicolon(;) after .innerHtml of ur code

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.