I am trying to limit the number of characters entered in a textarea as shown:
<div> @Html.TextAreaFor(x => x.StudentName, new { @maxlength = "1000" }) </div>
This works fine in Firefox and Chrome but the maxlength attribute doesn't work in IE. How do I do that??
All browsers support maxlength. However, this attribute can easily be removed/changed using DOM methods or, for example, with Firefox's Web Developer Toolbar.
There is no native max-length attribute for textareas.
The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> . This must be an integer value 0 or higher. If no maxlength is specified, or an invalid value is specified, the input or textarea has no maximum length.
When there is no max length specified the default is an unlimited number of characters for both textarea and text input.
The maxlength
attribute is not standard for <textarea>
in HTML 4.01. It is defined in HTML5 though but I guess IE doesn't implement it. To make it work across all browsers you could use javascript. Here's an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With