<textarea id= "Mytextarea" ></textarea><script>JQuery.fn.maxLength=function(max) { This. each (function(){ varType = This. Tagname.tolowercase (); varInputType = This. type? This. Type.tolowercase ():NULL; if(Type = = "Input" && inputtype = = "Text" | | inputtype = = "Password"){ //application of Standard maxlength This. MaxLength =Max; }Else if(Type = = "TextArea"){ This. onkeypress =function(e) {varOB = e | |event; varKeyCode =Ob.keycode; varHasselection = document.selection? Document.selection.createRange (). text.length > 0: This. SelectionStart! = This. Selectionend; return! ( This. value.length >= Max && (KeyCode > | | keycode = = | | keycode = 0 | | keycode = +) &&!ob.ctrl Key &&!ob.altkey &&!hasselection); }; This. onkeyup =function(){ if( This. value.length >max) { This. Value = This. value.substring (0, Max); } }; } });};// Use$ (' #mytextarea '). MaxLength (10);</script>
Limit the number of characters in a Text-area field