Textarea maxlength and jQuery

It’s just another one of those html4 oversights – textareas do not support the maxlength attribute! It’s frustrating as it’s often requested and can cause problems when people paste in huge amounts of data and submit it to your server but it’s easily fixed with JavaScript.

Using jQuery you can easily delegate events to each textarea and catch each user input, shortening it once it’s past the maximum value.

Here’s a quick fiddle to demonstrate:

Thankfully html5 now fully supports the maxlength attribute and this issue will soon be a thing of the past!

Leave a Reply