1

I want to auto resize the textarea width when I write inside it, with a max-width, like this code do for the input. http://jsbin.com/ahaxe it's possible?

3 Answers3

4

have you tried these may be these can help you

http://www.jacklmoore.com/autosize

http://www.technoreply.com/autogrow-textarea-plugin/

2

DEMO : http://jsfiddle.net/buM6M/1/

html:

<textarea id="t1" style='min-width:100px;min-height: 100px'>

</textarea>

 <div id="d1" style='max-width:200px;min-height:20px;display: none'>

</div>

js code :

  $("#t1").live({
keyup: function(e){

    $("#d1").text($(this).val());
    $(this).css("width", $("#d1").css("width"));
    $(this).css("height", $("#d1").css("height"));
}
});​

Set the dimensions of the div and textarea as per your requirement .

user1305989
  • 3,231
  • 3
  • 27
  • 34
0

use jquery autogrow plugin.

download autogrowtextarea.js and add to script

and add this css in head:

#id_of_textarea
{
height:auto;
width:width_of_textarea_you_want
}


$(function() {
$('#id_of_textarea').autogrow();
});

for avoiding scroll:

$('#id_of_textarea').css('overflow', 'hidden').autogrow()
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125