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!

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Not really adjustable for different fonts etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.