Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
Detect Enter keypress in html input without jquery

I just want to detect the enter input keypress on my android device. I found out that using jquery, we can do like below:

$('#inputText').keypress(function(event) {
var keycode = event.keyCode || event.which;
if(keycode == '13') {
    alert('You pressed a "enter" key in somewhere');    
}
});

But I don't want to use jquery. I want to use the traditional way like using

document.getElementById('inputText')

But I don't know how to add in the keypress event function. Do you guys have any idea?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Almost the same as in jQuery. Use eventListener and pass an argument e to the function to catch the event and it's keyCode.

var elem = document.getElementById('inputText');
elem.addEventListener('keypress', function(e){
  if (e.keyCode == 13) {
    console.log('You pressed a "enter" key in somewhere');   
  }
});
<input id='inputText'>

about 4 years ago · Santiago Trujillo Denunciar

0

document.getElementById("id").onKeyDown = function(event) {

    if (event.keycode === 13) {
        alert("return pressed");
    }

};
about 4 years ago · Santiago Trujillo Denunciar

0

Use event.key instead of event.keyCode!

const node = document.getElementById('inputText');
node.addEventListener('keydown', function onEvent(event) {
    if (event.key === "Enter") {
        // Do something
    }
});

Mozilla Docs

Supported Browsers

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda