You need to cancel the event!
event.preventDefault();
Just make sure to only do that when you're submitting the form - it'd be very easy to accidentally nuke all ability to type in the textarea at all ;)
Also, as a usability hint, I would suggest adding && !event.ctrlKey && !event.shiftKey
to your if
condition, as this allows people to enter line breaks manually as they would in many chat programs - if you explicitly don't want newlines, you may be better just using <input type="text" />
instead of <textarea>
, especially since this comes with built-in Enter-to-submit-form functionality.