Answers for "js on enter key press"

4

input enter button js

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

  
input.addEventListener("keyup", (event) => {
    if (event.key === "Enter") {
        // Cancel the default action, if needed
        event.preventDefault();
        // Trigger the button element with a click
        document.getElementById("myBtn").click();
    }
})
Posted by: Guest on April-27-2021
2

javascript detect enter press on input

var el = document.getElementById("myInputID");
el.addEventListener("keydown", function(event) {
    if (event.key === "Enter") {
        // Enter key was hit
    }
});
Posted by: Guest on January-06-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language