Textarea Size Limit w/ Counter

TEXTAREAs do not have a native way of specifying a maxlength like INPUTs so most developers use a little piece of JavaScript to help them out.  In the old days it was added inline and looked a little something like this:

<textarea onkeypress="return (this.value.length < 50);"></textarea>

This would limit your textarea to a max of 50 characters (it doesn’t support limiting copy/paste either but thats besides the point right now).

Nowadays, we need a little more than just something that silently limits our input.  We need a counter, we need feedback, we need interaction.   So naturally I turned to jQuery and wrote what I consider to be a very lightweight yet powerful plugin for limiting the length of any form field via any input method.  Optionally, a HTML element or jQuery selector can be provided to update a counter field.

Download

Demo

Posted on November 11, 2010 at 9:24 am by John Strickler · Permalink
In: HTML, jQuery