I want to limit the text box to 500 characters. For this, I used the maxlength attribute, but there is a compatibility problem in different browsers. To solve this problem, I used javascript function
function checkLength(fieldName,limit){
if(fieldName.value.length >= limit){
fieldName.value = fieldName.value.substring(0,limit);
}
}
I call this function in two events onKeyDown and onKeyUp . This fixes my problem somewhat, but when I copy and paste a line longer than 500 characters, it displays all the text and then trims to 500 on the keyboard. Is there a way to show exactly 500 characters when copying, rather than flickering.
source
share