javascript – limit the number of characters in a textarea

<script language="javascript" type="text/javascript">
function limitText(fieldLimit, countLimit, limitNum) {
if (fieldLimit.value.length > limitNum) {
fieldLimit.value = fieldLimit.value.substring(0, limitNum);
} else {
countLimit.value = limitNum - fieldLimit.value.length;
<form name="form_name">
<textarea name="sometext" onKeyDown="limitText(this.form.sometext,this.form.counter,100);"
</textarea><br />
(Maximum characters: 100)<br />
You have <input readonly type="text" name="counter" size="3" value="100"> characters left.

thanks to :

Share on Facebook

One thought on “javascript – limit the number of characters in a textarea”