Skip to navigation

textarea maxlength

By default, textareas do not have a maxlength area like input elements do. However, with jQuery and a simple script I wrote, you can set the maximum input length of a textarea.

Click here to preview textarea maxlength

What it looks like

There are two ways to set the maxlength with my script.

One way is to simply set the maxlength attribute.

<textarea maxlength="10"></textarea>

Or, if you prefer to have W3C-standard XHTML code (maxlength is not a standard textarea attribute), you can set it via jQuery.

<textarea id="limitMe"></textarea>

<script type="text/javascript">
  $('#limitMe').maxLength(10);
</script>

Step One: download jQuery and my script

In order to use my script, you must download jQuery and my small JavaScript file:

And include them on your page by pasting this in the head tag:

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="textarea-maxlength.js"></script>

Step Two: use it!

That's it! Now you can use the script however you want. If you want to use the maxlength attribute, you can now use it. Or, you can use the jQuery function maxLength to dynamically set the maximum input length. Passing an argument of zero will remove any maxLength rules.

More Questions?

As always, if you have any more questions, please email me. I am always glad to answer questions and work on custom scripts.