Greg answered the question, but this is an alternate way to do the same:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Teste Form Enter</title>
<script type="text/javascript" language="javascript">
function formHandler(e){
e.preventDefault();
console.log(e.target.elements.anything.value);
alert("Anything: "+e.target.elements.anything.value);
}
window.addEventListener("load", function(){
console.log("initialized...");
document.getElementById("test").addEventListener("submit", formHandler, true);
}, false);
</script>
</head>
<body>
<form action="#" name="test" id="test" method="get">
<label>Anything: </label>
<input type="text" name="anything" />
<br />
<button type="submit">Hit Enter</button>
</form>
</body>
</html>
And if you don't use form, or want to try by prototype, here is a start:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Teste Form Enter</title>
<script type="text/javascript" language="javascript">
Element.prototype.addEnterEvent = function(Func){
var me = this;
this.Func = Func;
this.gotFocus = false;
this.addEventListener("focus", function(){ me.gotFocus = true; }, false);
this.addEventListener("blur", function(){ me.gotFocus = false; }, false);
window.addEventListener("keyup", function(e) {
if(me.gotFocus && e.which==13) {
Func();
}
}, false);
}
function enterHandler(){
alert("Anything: "+document.getElementById("anything").value);
}
function ini(){
document.getElementById("anything").addEnterEvent(enterHandler);
//window.addEventListener("keyup", function(e){ console.log("Key: "+e.which); }, false);
}
</script>
</head>
<body onload="ini();">
<h1>OnEnter Test</h1>
<label>Anything: </label>
<input type="text" name="anything" id="anything" />
<br />
<button onclick="enterHandler();" type="button">Hit Enter</button>
</body>
</html>
If you're doing a login in Ajax, you can add to the last text box (pass or captcha) so when the user hit enter, the login function will be called.