I am using the following JavaScript function to limit the chars in a textarea:
function limit(element, max_chars)
{
if(element.value.length > max_chars)
element.value = element.value.substr(0, max_chars);
}
<textarea onkeyup="javascript:limit(this, 4000)"></textarea>
When entering long text in the textarea in Firefox and when the limit is reached, the focus is back to the top of the textarea and the textarea itself acts weirdly. In other browsers everything is fine. Is there a way to resolve that problem or another way to limit chars / remove extra chars with JavaScript?
Thank you!