Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form input field grows with overflowing text [duplicate]

Possible Duplicate:
Jquery growing and shrinking textarea

I want to achieve an effect where a text <input> will grow vertically when the text overflows. So instead of the beginning text being scrolled off, a new line starts, and the <input> grows vertically.

How could I achieve this using Javascript/jQuery/CSS/HTML/etc?

like image 650
Wiz Avatar asked Mar 07 '26 02:03

Wiz


2 Answers

You probably can use an autogrowing textarea styled as an input - DEMO

textarea {
    height: 20px;
    line-height: 20px;
    resize: none;
}​

There are numerous plugins exists to achieve the same effect - I used this for the demo.

like image 165
Zoltan Toth Avatar answered Mar 09 '26 16:03

Zoltan Toth


A pure Javascript way:

<textarea onkeyup="while(this.scrollTop > 0) {this.rows++;}"></textarea>
like image 26
benbai123 Avatar answered Mar 09 '26 17:03

benbai123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!