Trapping the Enter Key for HTML Forms
Sometimes it's confusing for users if an accidental press of the Enter key prematurely submits an HTML form. There are lots of ways to deal with this problem via javascript observation and validation of the form — here's a relatively simple way that works via jQuery
$("form input[@type=text]").bind("keypress", function(e) {
var code=e.charCode || e.keyCode;
return (code==13)?false:true;
});
The example code only traps the enter code on text boxes; you can expand the CSS selector at work to trap enter on other form elements. Obviously, you'll want NOT to trap the enter key on type="submit".
