Found this script:
function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) {return false;} } document.onkeypress = stopRKey;
Only issue, it also stops enter key being used in textarea. Which is a hassle.
I have toyed with using:
onkeypress="return handleEnter(this, event)"
But our forms are extremely complex, and I am looking for a cleaner way of doing things.
You need to check the
nodeName
ortagName
of the event target here, like this:I noticed after this was accepted that you are already using jQuery, you can just replace all your code above with this:
I think you can just change this line
to
If you use jquery (highly recommended) then this will automatically add the function to allow use of the enter key: