press enter after input javascript code example
Example 1: html javascript call function after pressing enter
var yourElement = document.getElementById("yourElement");
yourElement.addEventListener("keydown", function (e) {
if (e.code === "Enter") {
validate(e);
}
});
function validate(e) {
var text = e.target.value;
}
Example 2: input enter button js
var input = document.getElementById("myInput");
input.addEventListener("keyup", (event) => {
if (event.key === "Enter") {
event.preventDefault();
document.getElementById("myBtn").click();
}
})