How do you catch a carriage-return in a textarea and do a form post instead of a newline in the textarea?
To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character. Here is the HTML for the examples in this article. Copied!
Disabling enter key for the form keyCode === 13 || e. which === 13) { e. preventDefault(); return false; } }); If you want to prevent Enter key for a specific textbox then use inline JS code.
Capture the keystroke, verify if it is enter, and then look for the parent form
element and submit it:
$('#textAreaId').keydown(function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 13) {
$(this).parents('form').submit();
return false;
}
});
Check the above example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With