Whilst not the most racy of scripts, it may come in handy for web developers looking for a way to mimic the input tags built-in “maxlength” attribute.
Useful as a preliminary character length check before inserting user input into a fixed-width database column (although server side checking should always be done – but you know that already!).
Tested in Internet Explorer 5+ (Windows), Firefox, Mozilla and Opera.
View the textarea maxlength demo.

Previous Comments ~
Yep, I handle the
onblurevent in anything but Internet Explorer (which has a proprietaryonpasteevent that, in this case, is better than usingonblur).Actually, I’ve just noticed a bug in my code… well, not a bug as such but… we should really be removing the
onblurevent for Internet Explorer as we use it’s proprietaryonpasteevent.Et voila, I’ve altered the code to take this into consideration.
Thanks for the interest,
Brian.
P.S. The site is currently falling apart – I shall be redesigning soonish though so, please forgive any crazy CSS/whitespace badness you may encounter.
Pasting something removes all text after the pasted text (IE 6.0). Try again…
@ Simon: Fixed.
Is there a quick easy way to add a character counter to this script :) ?
Comments are currently closed for this article but feel free to email me with your input - I’d love to hear it.