1//https://stackoverflow.com/questions/6542413/bind-enter-key-to-specific-button-on-page
2//upvote them on stackoverflow
3//jquery------------------------------------------------------
4//answer by Chris Laplante
5$(document).keypress(function(e){
6 if (e.which == 13){
7 $("#button").click();
8 }
9});
10
11//pure javascript--------------------------------------------
12//answer by Alexander Kim
13window.addEventListener('keyup', function(event) {
14 if (event.keyCode === 13) {
15 alert('enter was pressed!');
16 }
17});
18
19//https://www.w3schools.com/howto/howto_js_trigger_button_enter.asp
20// Get the input field
21var input = document.getElementById("myInput");
22// Execute a function when the user releases a key on the keyboard
23input.addEventListener("keyup", function(event) {
24 // Number 13 is the "Enter" key on the keyboard
25 if (event.keyCode === 13) {
26 // Cancel the default action, if needed
27 event.preventDefault();
28 // Trigger the button element with a click
29 document.getElementById("myBtn").click();
30 }
31});