Adding an "onenter" event to an input element

Fonte: TecPorto
Saltar para a navegação Saltar para a pesquisa

Input elements in Javascript do not really have an "onenter" event. You can, however, simulate such an event by hooking the "onkeypress" event:

var l_input = document.getElementById("myelement");

l_input.onkeypress = function(p_event) { if(13 == p_event.keyCode) this.submit(); }


That's it. As simple as that.