Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 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
Introduction

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

Description:
  
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, asp.net. 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="http://www.w3.org/1999/xhtml">
<head>
<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);
}
}
</script>
</head>
<body>
<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>
</div>
</body>
</html>
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 Asp.net, C#.net, 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

13 comments :

Kashif Khan said...

thanks its good

Kashif Khan 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

Ramanji Singh said...

hi sir , u solve my question.how count length of character in editor control using asp.net

Ramanji Singh 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...

Thanks.

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.

Give your Valuable Comments

Other Related Posts

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