How to impose maxlength on textArea in HTML , Javascript

Posted by Rakesh Juyal on Stack Overflow See other posts from Stack Overflow or by Rakesh Juyal
Published on 2009-07-14T13:44:20Z Indexed on 2010/05/06 15:48 UTC
Read the original article Hit count: 285

Filed under:
|
|

I would like to have some functionality by which if i write

<textarea maxlength="50"></textarea>
<textarea maxlength="150"></textarea>
<textarea maxlength="250"></textarea>

it will automatically impose the maxlength on the textArea. If possible please donot provide the solution in JQuery.

Note: This can be done if i do something like this:

<textarea onkeypress="return imposeMaxLength(event, this, 110);" rows="4" cols="50">


function imposeMaxLength(Event, Object, MaxLen)
{
        return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40))
}

copied from another thread

But the point is I don't want to write onKeyPress and onKeyUp every time i declare a textArea.

© Stack Overflow or respective owner

Related posts about html

Related posts about JavaScript