0

I have several textarea elements in my html/php page. However, I need these textareas to resize dynamically. At the basic level, it need to expand when a user presses the enter key. How could I use javascript to make this happen? Any pointers are well appreciated. Thanks!

barell
  • 1,470
  • 13
  • 19
user3388884
  • 4,748
  • 9
  • 25
  • 34
  • 1
    possible duplicate of [Auto expand a textarea using jQuery](http://stackoverflow.com/questions/2948230/auto-expand-a-textarea-using-jquery) – adeneo Mar 26 '14 at 20:45

1 Answers1

1

This would be a basic implementation:

HTML:

<textarea id="a"></textarea>

JS:

var t = document.getElementById("a");
t.style.height = "80px";
t.onkeyup = function(e){
    if(e.keyCode == 13){
        t.style.height = parseInt(t.style.height) + 30 + "px";
    }
}

This is meant as something to start with.

Link to JSFiddle

Alethes
  • 922
  • 7
  • 9