0

I'm using Bootstrap, to disable the contents of a TextArea as such:

<td>
  <textarea class="form-control disabled" id="message"></textarea>
</td>

which works fine, apart from the fact that I need to control the height as well, based on the content being rendered into the control.

Are there any HTML 5 tricks, or CSS tricks I can use to dynamically resize the height of the control based upon the text? Or can this only be achieved using JScript

CSharpNewBee
  • 1,951
  • 6
  • 28
  • 64

2 Answers2

1

Try this:

DEMO

HTML:

<textarea id="ta" class="form-control disabled" id="message"></textarea>

CSS:

textarea {

    resize:none;
}

SCRIPT:

$("#ta").keyup(function (e) {
    autoheight(this);
});

function autoheight(a) {
    if (!$(a).prop('scrollTop')) {
        do {
            var b = $(a).prop('scrollHeight');
            var h = $(a).height();
            $(a).height(h - 5);
        }
        while (b && (b != $(a).prop('scrollHeight')));
    };
    $(a).height($(a).prop('scrollHeight') + 20);
}

autoheight($("#ta"));
Suganth G
  • 5,136
  • 3
  • 25
  • 44
0

Add following css:

textarea.form-control{
   position:absolute;
   height: auto;
}
Viswanath Donthi
  • 1,791
  • 1
  • 11
  • 12