showing results for - "javascript bind key to button"
Max
02 Sep 2018
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});
queries leading to this page
press enter actived a buttonhow to make event on pressing buttonjavascript keyup enter eventkeydown enter emit clickcan you bind the windows ket in html javascriptregister on enter key press onceenter event listener javascripthow to trigger a button by code with javascriptclick enter when input focus js eventkeycode for enter button in javascriptaddeventlistener input change press enterhow to add both a click and enter event in javascripthow to trigger a button in javascript on a keypresskeydown enter emit event clickadding the enter in js to registerjavascript get enter key pressno click with enter key on button javascripttrigger button click javascripthow to click button on enterjs on enter clickon key press return buttonon click enter jqueryjavascript bind key to buttonjavascript event when key enterenter event key jssubmit on press enter in javascripthtml bind a button to a keyjavascript detect enter keyon click or enter jqueryrun same code as click when enter javascriptjs key triggercreate key enter jsjquery on click or enteron enter press buttonadd enter button press and onclick in same addeventlistenerget event when user clicks enter on input htmlfunction html with enter key pressjavascript add event on enter keypress click button javascripthow to make a button press a key in javascriptsearch bar enter keyhow to trigger a button click event in javascriptbind key to a buttonjavascript simulate click enter eventdom on keyenterhtml input box enter eventlistenerbutton on enterhow to bind button element click to keyboardjavascript bind button with keyboardadding items using enter key in jshow to bind keys to buttons in javascriptjquery on click or on enterjavascript bind key to button