prevent a line break
<script src="https://code.jquery.com/jquery-3.3.1.js"></script> <!-- <textarea name="sample" cols="50" rows="10" wrap="soft"></textarea> --> <form> <textarea name="sample" cols="50" rows="10" class="cancel"></textarea> <input type="submit"> </form> <script> $('.cancel').bind('keydown', function(e){ if(e.which == 13){ return false; } }).bind('blur', function(){ var $textarea = $(this), text = $textarea.val(), new_text = text.replace(/\n/g, ""); if(new_text!= text){ $textarea.val(new_text); } }); </script>
I can no longer break line when I press enter key within the textarea.