limit number of characters entered in textarea
- by Abu Hamzah
here is the script does what i want but not exactly,
my question is, how can i stop user entering text once it reached the lmit of 255 characters?
var limit = 255;
var txt = $('textarea[id$=txtPurpose]');
$(txt).keyup(function() {
var len = $(this).val().length;
if (len > limit) {
//this.value = this.value.substring(0, 50);
$(this).addClass('goRed');
$('#spn').text(len - limit + " characters exceeded");
return false;
}
else {
$(this).removeClass('goRed');
$('#spn').text(limit - len + " characters left");
}
});
if there is a better way please let me know.