1

I have code in which its checking the number of characters entered in textarea and then it stops the typing when used this- $(this).val($(this).val().substr(0,charsLimit)); But problem here is that i want the user to use this method when max height of textarea reached and not when max characters reached. I do not understand how to do that. Help appreciated.

Code :

        var countHeight = 1;

        $(dividfortextbox).keypress(function(e) {
     var v = $(this).val();
     var vl = v.replace(/(\r\n|\n|\r)/gm,"").length; 

            if ((e.keyCode || e.which) == 13 && (hIncr * iheight) < checkdivheight && countHeight <= 15) {
            $(this).parent(dividfortext).css('height', (hIncr * iheight) + 'px');
            vWidth = 0;
            countHeight++;
            hIncr++;                

            }

            if (parseInt(vl/count) == chars && countHeight<= 15) {
            $(this).parent(dividfortext).css('height', (hIncr * iheight) + 'px');
            vWidth = 0;
            $(this).val(v + '\n');
            makeDivWidthStop = true;                
            count++;
            countHeight++;
            hIncr++;
            }    


    else {                                      
        vWidth = (vWidth+1); 
        if(vWidth * widthIncreaseSize > tWidth)
            tWidth = vWidth * widthIncreaseSize;

        if (tWidth < checkdivwidth && parseInt(vl/count) <= chars ) {

            $(this).parent(dividfortext).css('width', (tWidth) + 'px');
            divwidth=tWidth;
            }
        }

        if(countHeight > 15){           
        ??? What code should i apply here..?? ???
        } 


});
shabbir.rang
  • 279
  • 2
  • 4
  • 24
  • 1
    You'll need to calculate the maximum number of lines your textarea can hold based on font-weight, height, etc. Have a look at http://stackoverflow.com/questions/7519337/given-a-textarea-is-there-a-way-to-restrict-length-based-on-of-lines for an example. – Anthill Dec 04 '12 at 07:11
  • Thanks will surely check it. – shabbir.rang Dec 04 '12 at 08:05

0 Answers0