UPDATE: I am constructing the form via Javascript, so the form is not there on page load.
I have an input field with id="input"
, whenever the enter
key is pressed, the form gets submitted. So I tried handling it like this.
$("#input").keydown(function (e) {
if (e.keyCode == 13) {
alert("enter pressed");
return false;
}
});
However this does not work, there is no alert and the form still gets sent. How do I solve this?