qwertymk
qwertymk

Reputation: 35274

How to use the body's scrollbar for a textarea

If a user types more text than the textarea's area then the textrea gets a scrollbar.

Is there a way to just have the texarea extend so it uses the body's scrollbars?

Is this possible with css? jquery?

Upvotes: 0

Views: 67

Answers (3)

adeneo
adeneo

Reputation: 318182

Something like this maybe

http://jsfiddle.net/adeneo/cXQVu/

$("textarea").on('keyup', function() {
    var rows=$("textarea").val().split('\n').length;
    $(this).css('height', rows*20+'px');
});

Upvotes: 0

Alex
Alex

Reputation: 6406

Possible with jQuery or plain JavaScript.

http://jsfiddle.net/UDTQ5/2/

function resize(){
    var ta = $('#ta').get(0);
    ta.style.height = (ta.scrollHeight) + 'px';
}

Or:

function resize(){
    var ta = document.getElementById('ta');
    ta.style.height = (ta.scrollHeight) + 'px';
}

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382696

You can use textarea AutoGrow plugin (Demo/Download).

Upvotes: 0

Related Questions