Answers for "call function when user hits enter in textinput html"

0

call function when user hits enter in textinput html

// Get the input field
var input = document.getElementById("myInput");

// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(event) {
  if (event.code === "Enter") {
    // Cancel the default action, if needed
    event.preventDefault();
    // Trigger the button element with a click
    document.getElementById("myBtn").click();
    // ...or call a function
    myFunction();
  }
});
Posted by: Guest on April-06-2021

Code answers related to "call function when user hits enter in textinput html"

Code answers related to "Javascript"

Browse Popular Code Answers by Language