How to count numbers of line in a textarea?

This piece of script will change the height of the textarea to fit the text inside.

Var keyUpTimeout = false; // Required variables for performance var keyupTimer = 0; $("#text_textarea"). Keyup(function(e) { var cooldownTimeout = 500; //Set the cooldown time-out. The height check will be executed when the user // hasn't initiated another keyup event within this time var ths = this; function heightCheck(){ keyupTimer = false; // Reset height, so that the textarea can shrink when necessary ths.style.

Height = ""; // Set the height of the textarea var newheight = this. ScrollHeight + 2; ths.style. Height = newheight + "px"; } if(keyupTimeout){ //Has a cooldown been requested?

ClearTimeout(keyupTimer); //This+next line: Refresh cooldown timeout. KeyUpTimer = setTimeout(heightCheck, cooldownTimeout); return; //Return, to avoid unnecessary calculations } // Set a cooldown keyupTimer = setTimeout(heightCheck, cooldownTimeout); keyupTimeout = true; //Request a cooldown }); This piece of script will change the height of the textarea to fit the text inside. Update I have added an additional feature: To improve performance (changing the CSS height requires a significant amount of computer power), I have added a cooldown effect: The height check will only be executed when the user hasn't initiated a keyup event for 500 milliseconds (adjust this value to meet your wishes).

This is quit good. But in this code textarea height once increases does not decreases even the content is deleted or content height is decreased – Kuntal Basu Sep 18 at 10:38 1 Add this.style. Height=""; before var x = .... – Rob W Sep 18 at 10:43 Yes its working.. But I don't know why the performance is reduced somehow (bit slow responce) while writing.

I think because of calling the function on every keyup. Can it be corrected? – Kuntal Basu Sep 18 at 11:09 Updated answer.

I have added a performance boost :) – Rob W Sep 18 at 11:57.

Read this, Textarea Height increase TextAreaExpander (Demo) autoResize Plugin JQuery Elastic.

You could have elaboratedt he purpose of these references, rather than replying "read this, " – Rob W Sep 18 at 10:23 thanks for the comment,yes the same thing I want. But I don't want to use any plugin. Can you elaborate what the logic has been used in those plugins.

– Kuntal Basu Sep 18 at 10:25.

You should use the attribute wrap='hard' on your textarea.

Can you show a demo on jsfiddle.. – Baz1nga Sep 18 at 10:20 It seems that this attribute is proprietary.. My mistake. – Imad Moqaddem Sep 18 at 10:35.

I write this code. What about it.. $("#text_textarea"). Keyup(function(e) { var textarea_height = Number($(this).

Css('height'). Replace("px", ""))+4; var scroll_height = this. ScrollHeight; if(textarea_height Css('height' ,""); var x = Number(scroll_height) + 3; if(x!

= $(this).height()) $(this). Css("height", x+"px"); } }).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions