call function when user hits enter in textinput html

Solutions on MaxInterview for call function when user hits enter in textinput html by the best coders in the world

showing results for - "call function when user hits enter in textinput html"
Angelo
04 Apr 2018
1// Get the input field
2var input = document.getElementById("myInput");
3
4// Execute a function when the user releases a key on the keyboard
5input.addEventListener("keyup", function(event) {
6  if (event.code === "Enter") {
7    // Cancel the default action, if needed
8    event.preventDefault();
9    // Trigger the button element with a click
10    document.getElementById("myBtn").click();
11    // ...or call a function
12    myFunction();
13  }
14});