I want to restrict a textarea to 500 characters. For this I used a maxlength attribute but there is some compatability issue across different browsers. To resolve this I used a javascript function
function checkLength(fieldName,limit){
if(fieldName.value.length >= limit){
fieldName.value = fieldName.value.substring(0,limit);
}
}
I am calling this function on two events onKeyDown and onKeyUp. This somewhat fixes my issue but when I copy and paste a string with length more than 500 chars it shows all the text and then trims to 500 on key up. Is there any way to show exactly 500 chars while copy pasting whithout flickering.