This question already has an answer here:
How can I set the maxlength
in a textarea
? And why maxlength
is not working properly in textarea
?
This question already has an answer here:
How can I set the maxlength
in a textarea
? And why maxlength
is not working properly in textarea
?
resize:none; This property fix your text area and bound it. you use this css property id your textarea.gave text area an id and on the behalf of that id you can use this css property.
maxlength is only valid for HTML5. For HTML/XHTML you have to use JavaScript and/or PHP. With PHP you can use strlen for example.This example indicates only the max length, it's NOT blocking the input.
Before HTML5, we have an easy but workable way: Firstly set an maxlength attribute in the textarea element:
Then use JavaScript to limit user input:
Make sure the bind both "input" and "propertychange" events to make it work on various browsers such as Firefox/Safari and IE.
If you are using HTML 5, you need to specify that in your
DOCTYPE
declaration.For a valid HTML 5 document, it should start with:
Before HTML 5, the
textarea
element did not have amaxlength
attribute.You can see this in the DTD/spec:
In order to limit the number of characters typed into a
textarea
, you will need to use javascript with theonChange
event. You can then count the number of characters and disallow further typing.Here is an in-depth discussion on text input and how to use server and client side scripting to limit the size.
Here is another sample.
Before HTML5 it's only possible to check this with JavaScript or by a server-side verification (better, because JavaScript obviously only works with JavaScript enabled...). There is no native max-length attribute for textareas.
Since HTML5 it's a valid attribut, so defining your doctype as HTML5 may help. I don't know if all browsers support this attribute, though: