Skip to content

Instantly share code, notes, and snippets.

@mildfuzz
Created November 2, 2012 11:30
Show Gist options
  • Select an option

  • Save mildfuzz/4000352 to your computer and use it in GitHub Desktop.

Select an option

Save mildfuzz/4000352 to your computer and use it in GitHub Desktop.
Ensures a max length is adhered to in older browsers
var textareas = document.getElementById('user_summary');
for (var i = textareas.length; i--;) {
if (textareas[i].getAttribute('maxlength') && !textareas[i].maxlength) {
var max = textareas[i].getAttribute('maxlength');
textareas[i].onkeypress = function(event) {
var k = event ? event.which : window.event.keyCode;
if(this.value.length >= max) if(k>46 && k<112 || k>123) return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment