Hallo,
alternativ gäbe es auch noch onKeyDown was ich allerdings für doof halte :P
Wenn man ohnehin ein Formular hat, das man gelegentlich auch abschicken will, gebe ich dir Recht. Aber wenn es gar kein Formular gibt, nur input-Felder und Buttons, dann benutze ich onkeydown für solche Features.
Beispiel:
document.getElementById("okButton").onclick = function () {
// hier die Action...
}
document.getElementById("inputBox").onkeydown = function (e) {
e = e || event; if ((e.which || e.keyCode) == 13) { document.getElementById("okButton").click(); }
};
<input id="inputBox" type="text"><input id="okButton" type="button" value="OK">
Warum sollte man auch ein Formular erstellen, das man nie abschicken will? Das halte ich für blöd ;-)
Gruß, Don P