Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript bind key to button

//https://stackoverflow.com/questions/6542413/bind-enter-key-to-specific-button-on-page
//upvote them on stackoverflow
//jquery------------------------------------------------------
//answer by Chris Laplante  
$(document).keypress(function(e){
    if (e.which == 13){
        $("#button").click();
    }
});

//pure javascript--------------------------------------------
//answer by Alexander Kim
window.addEventListener('keyup', function(event) {
  if (event.keyCode === 13) {
    alert('enter was pressed!');
  }
});

//https://www.w3schools.com/howto/howto_js_trigger_button_enter.asp
// Get the input field
var input = document.getElementById("myInput");
// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(event) {
  // Number 13 is the "Enter" key on the keyboard
  if (event.keyCode === 13) {
    // Cancel the default action, if needed
    event.preventDefault();
    // Trigger the button element with a click
    document.getElementById("myBtn").click();
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: return random rows sqlite 
Javascript :: join two arrays angular 
Javascript :: get status bar height react native 
Javascript :: how to always run validators mongoose 
Javascript :: splidejs pauseOnHover 
Javascript :: javascript check if number is a power of 2 
Javascript :: js canvas rectangel 
Javascript :: javascript base64 encode file input 
Javascript :: nodejs format text 
Javascript :: jquery download image from url 
Javascript :: toggle css class in javascript 
Javascript :: curl post json file 
Javascript :: how to detect onend reach of scrollview in react native 
Javascript :: allow cors express 
Javascript :: settime out with promise 
Javascript :: remove appended element jquery 
Javascript :: pymongo add json to collection 
Javascript :: js window active 
Javascript :: angular goto top of page 
Javascript :: swapping elements in an array 
Javascript :: require express 
Javascript :: json merge 
Javascript :: random string js 
Javascript :: jquery visible 
Javascript :: replace double slash with single slash node.js 
Javascript :: push notification javascript 
Javascript :: js json to object 
Javascript :: flutter access json object inside object 
Javascript :: check if message mentions users discord js 
Javascript :: how to modify external json file javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =