1

I have a working text area that autoresize height according to input using JS function, I tried to add JS function to disable ENTER behavior adding new line but didn`t work.

<textarea id="title" name="title" class="autosize" placeholder="new post title" cols="42" rows="1">Post title</textarea>

http://jsfiddle.net/ihabovich/kepjdgnL/

  • 2
    Works for me in Chrome. However, I do recommend you move the keypress event handler inside the document ready function; just after your keyup handler. – ventaur Dec 28 '14 at 19:52
  • @ventaur Moving the keypress event handler inside the document ready function got it fixed. Thanks for clearing the issue. –  Dec 28 '14 at 23:41

1 Answers1

1

Are you using internet explorer perhaps. It seems to work fine in the three browsers I was able to test in (Safari, Chrome and FF)

If you are using IE then have a look at this solution. event.preventDefault() function not working in IE

Community
  • 1
  • 1
Giwan
  • 1,564
  • 14
  • 17
  • The only still issue is the paste input still have line breaks allowable. –  Dec 28 '14 at 23:49
  • 1
    In that case, you will want to filter out line breaks after a paste event. Javascript will allow you to remove the \n characters. This is a bit tricky though because these can be different between windows and other OS. http://www.textfixer.com/tutorials/javascript-line-breaks.php – Giwan Dec 29 '14 at 08:04
  • JS was not precise handling the method. More accurate done through CSS: white-space: pre-line; –  Dec 29 '14 at 14:12