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

Unknown said...

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

Amit Kumar Rath said...

I am extracting the date from a textbox in the form dd-mm-yyyy(type is DateTime) and time from another textbox but
in the form of hh:mm:ss(type is TimeSpan)and concating both the extracted values to store in a variable of type "DateTime".
So, my final datetime variable stores a value in the form of dd-mm-yyyy hh:mm:ss.The problem is the textbox values are in
hh:mm form but its taking the valus in hh:mm:ss form due to the type TimeSpan.

But i want the value in the form of dd-mm-yyyy hh:mm.

Hows to do it???

DateTime finalvalue= DateTime.parse(txtDate.text)+ " " +TimeSpan.Parse(txtTime.text);

Unknown said...

not work

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

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