kiaaanabal kiaaanabal - 7 months ago 28
HTML Question

Wrap text within in a text input

I am needing to wrap text within a text input. I know that textareas have this functionality by default, but I need to use a text input to allow for submit on enter. Pressing enter in a textarea just brings you to a new line.

I've tried word-wrap and word-break, but those don't work. I'm assuming this is impossible, but I don't want it to be haha :)

Any help is appreciated!

Answer

Since you cannot wrap an input your best option would be to disable the enter in a text area, see fiddle: https://jsfiddle.net/c259LrpL/11/

<textarea id="something"></textarea>
<script>
$("#something").keydown(function(e){
if (e.keyCode == 13 && !e.shiftKey)
{
  e.preventDefault();
  return false;
  }
});
</script>