0

So I have a text input.

<input type="text" id="myText" style="width: 400px; height: 20px;">

I want to turn it into a textarea when there is no longer enough space to type stuff in.

Once the text input has run out of space, I want to change it to something like this:

<textarea id="myText" style="width: 400px; height: 40px; resize: none;"></textarea>

And when the space in the textarea has run out, its height will be changed again:

<textarea id="myText" style="width: 400px; height: 60px; resize: none;"></textarea>

The main problem that I am facing is turning the original input text into a textarea. Is there an easy way besides trial and error to really detect if the space has run out? And how do I change my text input into a textarea once the space has run out?

Thanks.

3
  • @PatrickEvans Not really. I want to turn the text input into textarea once it runs out of space. Not auto-expanding the textarea. I already know how to auto-expand it. Commented Apr 11, 2014 at 10:13
  • on textchange event check length and on increasing particular length convert it to textarea. and on decreasing length revert it. Commented Apr 11, 2014 at 10:15
  • Seems easier to just use an expanding textarea, instead of trying to switch between the two, but ok. are you wanting it to switch back to a textbox if they end up deleting certain amount? Commented Apr 11, 2014 at 10:16

1 Answer 1

1

I think having two different elements complicates things, have a look at only having a textarea element and then expand it as needed. There's a jQuery plugin you might want to look into if you're ok with using jQuery: http://www.jacklmoore.com/autosize/

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

Comments

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.