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 - Show Number of Characters Remaining in Textbox or Textarea

Feb 28, 2013

Here I will explain how to show number of characters remaining in textbox or textarea using JavaScript

In previous articles I explained JavaScript restrict user to enter only numbers, JavaScript allow limited characters in textarea, JavaScript remove special characters from textbox JavaScript validations for phone, email and many articles relating to
JavaScript, jQuery, Now I will explain how to show number of characters remaining in textbox or textarea using JavaScript.

To implement this we need to write the code like as shown below

<html xmlns="">
<title>Limit the number of characters in textbox or textarea</title>
<script type="text/javascript">
function LimtCharacters(txtMsg, CharLength, indicator) {
chars = txtMsg.value.length;
document.getElementById(indicator).innerHTML = CharLength - chars;
if (chars > CharLength) {
txtMsg.value = txtMsg.value.substring(0, CharLength);
<div style="font-family:Verdana; font-size:13px">
Number of Characters Left:
<label id="lblcount" style="background-color:#E2EEF1;color:Red;font-weight:bold;">140</label><br/>
<textarea id="mytextbox" rows="5" cols="25" onkeyup="LimtCharacters(this,140,'lblcount');"></textarea>
Live Demo

For live demo check below example

Number of Characters Left:

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


Viral Story Insight said...

thanks its good

Viral Story Insight said...

thanks its good

sravan said...

It was not working while using master page

vijay said...

Thanks a lot dude ...
@ sravan: it's working for me with master page

Anonymous said...

hi sir

Unknown said...

hi sir , u solve my count length of character in editor control using

Unknown said...

sir give me solution immediatly..

Anonymous said...

Doesn't work if you use right click and paste value in the textbox...

Anonymous said...

Thanks For The Code.
It is really helpful.

rajesh said...

good example but when i right click paste data then it showing that exceded text also

Anonymous said...

Apply the the script on onblur="LimtCharacters(this,140,'lblcount');" to make it more better.

Vaiyapuri Periyasamy said...


anudeep said...

How to limit the number of words to display in browser.For example we have a paragraph of two lines we can display it on large screens but in small screen we want to display only one line only so what should we do to hide remaining lines.

Peggy Gunn Milligan said...

Thank you! I know this is a couple of years old, but it is the first solution that I have found that works for me on an aspx page when I changed the textarea to a textbox. I gather that data on the server side to save to the database so didn't want to change the control I was using. With this being a content page and boxes needed to monitor on the main page and multiple pop-ups I was pulling my hair out. This did it. Thank you so much!

Kuch Jano said...

Thank you suresh..!!

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.