1

How can I have the same action when I press the Enter key as if I click the button? When I press the Enter key, I want it to run the same script as when I do the "onclick" event.

<button type="button" value="Login" class="btn green uppercase" onclick="formhash(this.form, this.form.password);">Login</button>
Pang
  • 9,564
  • 146
  • 81
  • 122
Freddos
  • 35
  • 6
  • 1
    Duplicate of http://stackoverflow.com/questions/155188/trigger-a-button-click-with-javascript-on-the-enter-key-in-a-text-box – Chris Happy Feb 02 '17 at 00:04
  • That might be the case but if you´re not good with javascripts and dont want to waste hours of trying to play around without the result you want it is faster to ask here, right. Not all things are obvious for everyone. – Freddos Feb 02 '17 at 00:49

1 Answers1

0

For your specific example:

document.body.addEventListener('keydown', function(e) {
  if (e.keyCode == 13) {
    formhash(this.form, this.form.password);
  }
});
Chris Happy
  • 7,088
  • 2
  • 22
  • 49