Skip to content Skip to sidebar Skip to footer

Textarea Maximum Length?

Is it possible to set the maximum length of text in a TextArea?

Solution 1:

Something interesting is that HTML5 have added the feature of maxlength to textarea, if HTML5 is something you are ok to use right now.

W3C official documentation

Demo:

<textareamaxlength="20"></textarea>

Solution 2:

You can use following format in HTML

<inputtype="text" maxlength="13">

Solution 3:

If you are using jQuery, use this plugin http://www.stjerneman.com/demo/maxlength-with-jquery

Solution 4:

This solution is re-usable for all text areas via one function and it doesn't inform the user that he/she is typing too many characters, it prevents them from doing so, sort of like maxlength

The Function:

<scriptlanguage="javascript"type="text/javascript">functionimposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
</script>

Implementation:

<textareaname="myName"onkeypress="return imposeMaxLength(this, 15);" ><textarea>

Solution 5:

The Textarea doesn't accept the maxlength.

I have created a javascript function to handle this on onchange event. On one of my solutions I avoid the submit on form onsubmit event.

The code bellow will avoid submit if the textarea has more than 255 caracters

<script>functioncheckSize(){
    var x = document.getElementById('x');
    return x.value.length <= 255;
}
</script><formonsubmit="return checkSize()"><textareaid="x"><textarea></form>

Post a Comment for "Textarea Maximum Length?"