NS6+ IE5+ Opera 7+

Textarea Maxlength script

Author: Dynamic Drive

Description: This is a simple but effective script for extending your textarea with a maxlength attribute, so the user's input cannot exceed a certain number of characters. Works with any number of textareas on the page.

Demo: Try typing in the below textareas.

This textarea has a maxlength of 10:

This textarea has a maxlength of 30:

Directions: Developer's View

Step 1: Add the below script to the <HEAD> section of your page:

Select All

Step 2: Inside any textarea you wish to add a "maxlength" attribute to, simply do the following:

<textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>

The part in red is what you should add, with "40" obviously being the maximum number of characters accepted by this textarea.


Wordpress Users: Step by Step instructions to add ANY Dynamic Drive script to an entire Wordpress theme or individual Post