The following code works great for locking the keyboard in IE6 and IE8 when a textarea reaches a certain length. Of course, it doesn’t work on other browsers, and I can’t figure out a way to turn it into a jQuery function that will work cross-browser. Is it possible to get the same behavior in FireFox and Webkit browsers?
function checkLength(fld, maxLength){
if(fld.value.length > maxLength-1){
event.returnValue = false;
}
}
<p><textarea name="third" id="third" onkeypress="checkLength(this, 10);">hello</textarea></p>
I’m going to plug my own blog here –
http://blog.jbstrickler.com/2010/11/textarea-size-limit-w-counter/
If you want something very simple, you could do –
Where 50 is how many characters you want to limit.
EDIT: Per Jason’s comment, I didn’t want to give the wrong impression here that inline scripting is okay…