5

Is there a way to make a HTML textarea element to allow only one line?

I want to do this because I will have a button to expand it, but if user is allowed to enter multiple lines when the textarea is not expanded (only 1 row) it doesn look very nice, and if I use a textbox for the not expanded state, it looks weird when I replace it with the textarea and expand it with animation.

gtilx
  • 2,055
  • 4
  • 17
  • 21
  • possible duplicate of [how remove wordwrap from textarea](http://stackoverflow.com/questions/657795/how-remove-wordwrap-from-textarea) – Yi Jiang Oct 10 '10 at 15:10
  • 1
    No, my question have nothing to do with carriage returns, but with new lines. – gtilx Oct 10 '10 at 16:25

4 Answers4

2

You can put jQuery to use to create such field effect. See the demo here.

http://www.9lessons.info/2010/03/facebook-like-expanding-textbox-with.html

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
1

No.

You can stack the elements, then show the textarea first and remove the textbox right away. I guess it would be the workaround.

Example on how to stack elements on jsFiddle.

BrunoLM
  • 97,872
  • 84
  • 296
  • 452
1

As far as I know you'd need to use javascript to monitor and prevent the enter key.

Blair McMillan
  • 5,299
  • 2
  • 25
  • 45
-1

Not in plain HTML, however, if you use JavaScript you could do it.

Blake
  • 756
  • 3
  • 16
  • 34