I was looking for a way to do this, got a few scripts, but none of them is working for me.
When I hit enter in my textboxes, it shouldn't do anything.
I have tried a few JavaScript and jQuery scripts, but nothing is working for me.
$(document).ready(function() {
$('#comment').keypress(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
}
});
$('#comment').keyup(function() {
var txt = $('#comment').val();
$('#comment').val(txt.replace(/[\n\r]+/g, " "));
});
});
If you want to prevent Enter key for specific textbox then use inline js.
<input type="text" onkeydown="return (event.keyCode!=13);"/>
It stops user to press Enter in Textbox & here I return false which prevent form to submit.
$(document).ready(function()
{
// Stop user to press enter in textbox
$("input:text").keypress(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
return false;
}
});
});