Click here to Skip to main content
15,744,304 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have textArea htmlControl for which i have set Maximum charter count to 150.
I need a dynamic text counter that will decrement the text count as i type text in it.

any link?
Updated 5-May-11 20:21pm
koolprasad2003 6-May-11 2:21am    
Increase Readability
spydeehunk 6-May-11 2:25am    
this is the full code i just did it my application and paste it. you want me do proper commenting . but here this is not required you can just copy the code in yr page it will work fine

This[^] could probably help you get started and create what you want.
Share this answer
Sergey Alexandrovich Kryukov 6-May-11 2:27am    
Not so good solution. You need to prevent further typing when limit is exceeded and allow only backspace. I also don't see indication.

I've just implemented it all, please see.
Looks like you are looking for these:
Javascript Dynamic Text Area Counter[^]
Check TextArea Length[^]

If needed, look here for more[^].
Share this answer
Sergey Alexandrovich Kryukov 6-May-11 2:29am    
I cannot see complete solution here.

Please see my comments and my Solution. It shows how to do it all.
This is a full sample:

      <script type="text/javascript"><!--
         function counter(eventInstance, max) {
            eventInstance = eventInstance || window.event;
            key = eventInstance.keyCode || eventInstance.which;
            tarea = document.getElementById("tarea");
            output = document.getElementById("output");
            allowed = max-tarea.value.length;
            output.innerHTML = allowed + " remainin";
            if (allowed <= 0 & key != 8) {
               eventInstance.returnValue = false;
               return false;
         } //filterOut

<textarea id="tarea" onkeypress="counter(event, 150);"></textarea>
<div id="output" />


This solution shows how to output value, and how to prevent entering more characters if the limit it exceeded. However, backspace is allowed (and delete is never blocked).

Share this answer
Abhinav S 6-May-11 9:42am    
Good solution. 5.
Sergey Alexandrovich Kryukov 6-May-11 11:28am    
Thank you, Abhinav,

you just take the textarea length and do the decrement of the textarea charter count.

Share this answer
Sergey Alexandrovich Kryukov 6-May-11 2:28am    
Not just it. Please see my comments and Solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900