Disable Enter Key On Page, But Not In Textarea
Found this script: function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null
Solution 1:
You need to check the nodeName
or tagName
of the event target here, like this:
if (evt.keyCode == 13 && node.nodeName != "TEXTAREA") { returnfalse; }
I noticed after this was accepted that you are already using jQuery, you can just replace all your code above with this:
$(document).keypress(function (e) {
if(e.which == 13 && e.target.nodeName != "TEXTAREA") returnfalse;
});
Solution 2:
I think you can just change this line
if (evt.keyCode == 13 && node.type == "text") {
returnfalse;
}
to
if (evt.keyCode == 13 && node.type != "TEXTAREA") {
returnfalse;
}
Solution 3:
If you use jquery (highly recommended) then this will automatically add the function to allow use of the enter key:
$("textarea").focus(function () {
$(this).keypress(handleEnter);
});
Post a Comment for "Disable Enter Key On Page, But Not In Textarea"