Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
How to get data from the html input after the user has pressed enter or clicked elsewhere?

Js has a built-in function that allows you to retrieve data from an input when a user enters something into it: input.addEventListener("input", myFunction()). But it does not suit me, because it is executed every time the user enters at least one character. Instead, I need an approach in which the function would be called only when the user typed something and then pressed enter or clicked on a page in different place.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use the focusout event which fires when an element is about to lose focus and for the enter key you could check the event.key within the keypress event which is fired when a key that produces a character value is pressed down. like so:

input.addEventListener("keypress", function (e) {
   if (e.key === 'Enter') {
     // code for enter
   }
});

focusout - https://developer.mozilla.org/en-US/docs/Web/API/Element/focusout_event

keypress - https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the following methods for this:

  1. use onblur for the input elements. This will trigger once the user clicks anywhere outside of that input box.

  2. use onsubmit for the form. This will trigger when the user presses enter or submits the form in anyway.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda