I noticed the new Facebook way of sending comments on status. Basically when you write your comment you have no buttons to click but the “enter” key to press in order to submit the comment. Now I’d like to make this thing too. And I was thinking about the possible solutions. It comes to my mind that <input> are submitted with the enter button pressed, but that textarea are not.
- Either I write an input (type text) and set an height witch covers more than a row
- Or I have to add a textarea and somehow submit that form when the user press enter.
Which is the best? And if the answer = second, how could I do that?
It depends how you define best.
The first is best if you want a really easy solution that doesn’t require javascript
The seconds is best if you wish to allow linebreaks in the text.
If you wish to use the text area solution you can do something like this: (uses jQuery)
The good thing about this solution is that it still allows people to do linebreaks, if they just hold in the shift key when they hit enter. Just like on skype.
Live example here: http://jsfiddle.net/MEtGg/