Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!