php - Set the max amount of chars in a textarea -


i try limit number of chars can added textarea. know take number of chars sub-string want indicate user text has reached maximal length.

the maxlength-attribute seems want ie not support on our current version (i think supported somewhere around ie9)

to circumvent problem integrated onkeypress="return(this.value.length < 160);" works fine prevent long text prevents erasing or reedit of text huge problem.

just add javascript working me , useful see left character.

function textcounter(field,cntfield,maxlimit) {       if (field.value.length > maxlimit) // if 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 below span 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> 

Comments