Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maxlength for text area doesn't work in IE

Tags:

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??

like image 650
Infant Dev Avatar asked Feb 02 '12 08:02

Infant Dev


People also ask

Does Maxlength work all browsers?

All browsers support maxlength. However, this attribute can easily be removed/changed using DOM methods or, for example, with Firefox's Web Developer Toolbar.

Can I use textarea Maxlength?

There is no native max-length attribute for textareas.

How do you give a field to Maxlength?

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.

Is there any limit in HTML textarea?

When there is no max length specified the default is an unlimited number of characters for both textarea and text input.


1 Answers

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.

like image 188
Darin Dimitrov Avatar answered Sep 29 '22 22:09

Darin Dimitrov