Counting the characters dynamically inside a textarea and setting a limit

We can write one textarea counter to show our visitors the number of text or characters they entered inside the textarea. This counter will keep updating it self on entry or delete of any character inside the textarea. The counter shows decreasing value showing how many more characters can be entered or left to be entered. This way the visitor can keep track on its text entry based on the maximum length limit shown by the counter.

Every time as the text entered inside the textarea we can't send data to server so we will execute this program by using client side JavaScript.

Inside the Textarea we will use to event handlers, one is onKeyPress and other is onKeyDown. Both the event handlers will trigger one function in JavaScript. Inside this function we will check the length of the characters inside the textarea by using my_form.my_text.value.length with the maximum value set. If the length is less than the maximum set value then we can update the counter but if length is equal to or more than the set value then we can trim ( or remove ) the extra input from the string. We also can display one alert message if required.