html javascript call function after pressing enter

Solutions on MaxInterview for html javascript call function after pressing enter by the best coders in the world

showing results for - "html javascript call function after pressing enter"
Pablo
10 Mar 2018
1var yourElement = document.getElementById("yourElement");
2yourElement.addEventListener("keydown", function (e) {
3    if (e.code === "Enter") {  //checks whether the pressed key is "Enter"
4        validate(e);
5    }
6});
7
8function validate(e) {
9    var text = e.target.value;
10    //validation of the input...
11}