Home | All Questions | alt.html FAQ >

How do I limit the number of characters in a textarea?

<script type="text/javascript">
    function checkInputSize(which, maxsize) {
        which.value = which.value.substring(0, maxsize);

<textarea rows="10" cols="30"
onchange="checkInputSize(this, 255)">

Where 255 is the maximum number of characters allowable. JavaScript cannot effectively set a limit on anything. Any browser that supports JavaScript lets the user disable the support too.

(Thanks to Ludovic Rebouillat for the correction!).

Recommended Resources


Related Questions