This is my first attempt to build a jQuery plugin and maybe there’s already another plugin that does the same thing but it have been a really nice exercise.
This plugin will give you the method setCounter([maxLength]). If you call it on a textarea field you will get a counter that gets updated every time the user write a character.
The maxLength parameter is not mandatory so if it’s undefined you will get a simple character counter like this:
while if you pass an integer to the method the user won’t be able to write a number of character greater than maxLength and you will get a counter like this:
This is the code. Save it in a text file named something like jquery.textareaCharacterCounter.js and include it in your page: