Q:

Set the max amount of chars in a textarea

I try to limit the number of chars that can be added to a textarea. I know I could just take the number of chars with a sub-string but I want to indicate the user that his text has reached the maximal length.
The maxlength-attribute seems to do exactly what I want but IE does not support it on our current version (I think its supported somewhere around IE9)
To circumvent this problem I integrated onKeyPress="return(this.value.length < 160);" which works fine to prevent a too long text however it also prevents the erasing or reedit of the text which is a huge problem.

A:

just add this javascript it is working for me and also useful to see left character.
function textCounter(field,cntfield,maxlimit) { 

    if (field.value.length > maxlimit) // if too long...trim it!
    {field.value = field.value.substring(0, maxlimit); }
    // otherwise, update 'characters left' counter
    else
    {       
    //cntfield.value = maxlimit - field.value.length; 
    cntfield.value = field.value.length
    }

}

html file

Also please add on onKeypress event of text area with below span to manage remaining character 
<span class="alignright comments-req"><input type="text" name="textlen" id="textlen" value="0" class="counter-textfield">/500 <?php  echo $this->translate('LABEL_CHARACTER_USED');?></span>

