I have a piece of code
$('[maxlength][minlength]').focus( function(){ $(this).after('<div></div>');obj=$(this).parent().find('div') } ).bind('keyup focus', function(){ if ($(this).attr('minlength')>this.value.length){ obj.text(($(this).attr('minlength')-this.value.length)+' ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ² Π½ΡΠΆΠ½ΠΎ'); }else{ obj.text(($(this).attr('maxlength')-this.value.length)+' ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ² ΠΎΡΡΠ°Π»ΠΎΡΡ'); if (this.value.length>$(this).attr('maxlength')){ this.value=this.value.substring(0,this.getAttribute('maxlength')); } } } ).blur( function(){ obj.remove(); } );
Its essence is that when focusing on objects in which there are maxlength and minlength attributes, after them a DIV is created which displays how many characters are needed and left.
The essence of the problem is that this script only works on objects created in advance (put in $(document).ready()
), and I need it to always work.