Reputation: 73424
I want to allow the user to press enter and save the text of the textarea, but I want the newline NOT to get applied in the text of the textarea. Is that possible?
Here is my jsFiddle.
e.stopPropagation();
just seems to be not enough!
Upvotes: 1
Views: 913
Reputation: 2047
I just tried this code here in JSFiddle and it works fine for me
$('textarea').keypress(function(event) {
if (event.keyCode == 10 || event.keyCode == 13) {
event.preventDefault();
}
});
Upvotes: 0
Reputation: 660
Try this:
$('#cagetextbox').keypress(function(e){return CancelNewLine(e);});
function CancelNewLine(e)
{
var keynum;
if(window.event) // IE
keynum = e.keyCode;
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which;
return (keynum != 13);
}
Upvotes: 0
Reputation: 2690
What you're after is e.preventDefault()
. Stop propagation just stops bubbling up the DOM tree.
Upvotes: 1