I have a textarea where it should not be possible to input line breaks by pressing enter. How can I disable enter in my textarea?
That is the code:
<textarea name="textarea" style="width:250px;height:150px;"></textarea>
I have a textarea where it should not be possible to input line breaks by pressing enter. How can I disable enter in my textarea?
That is the code:
<textarea name="textarea" style="width:250px;height:150px;"></textarea>
Don't forget to use the keydown event instead of the click event
   $("input").keydown(function(event) {
    if (event.keyCode == 13) {
        event.preventDefault();
    }
});
 
    
    If you use jquery in your web application you can do fallowing trick to disable enter key.
$('textarea').keydown(function(e) {
    if(e.which == 13) { return false; }
});
else you can use this
document.getElementById('textarea_id').addEventListener('keydown', function(k){
    if(k.keyCode == 13) return false;
});
I hope this will help you!
 
    
    Use event.preventdefault and next do what you like. For example
<script>
$("textarea").click(function(event) {
  if (event.keyCode == 13) {
        event.preventDefault();
    }
});
</script>
