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
  • 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, 2014 at 19:52
  • @ventaur Moving the keypress event handler inside the document ready function got it fixed. Thanks for clearing the issue.
    – user1556571
    Dec 28, 2014 at 23:41

1 Answer 1

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

3
  • The only still issue is the paste input still have line breaks allowable.
    – user1556571
    Dec 28, 2014 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. textfixer.com/tutorials/javascript-line-breaks.php
    – Giwan
    Dec 29, 2014 at 8:04
  • JS was not precise handling the method. More accurate done through CSS: white-space: pre-line;
    – user1556571
    Dec 29, 2014 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.