title: Hitting enter instead of clicking submit is not working in JavaScript
body: <p>I am trying to allow my user to hit enter in the input field which should trigger the same click event as if they had clicked on the &quot;submit&quot; button with their mouse.</p>
  <pre><code>document.getElementById(&quot;input&quot;).addEventListener(&quot;keyup&quot;, function() {     
      if (KeyboardEvent.code == &quot;13&quot;) {                                        
          document.getElementById(&quot;button&quot;).click();                          
      }
  });
  </code></pre>
  <p>However the keycode doesn't work. The content of the function works when I do KeyboardEvent.code != &quot;13&quot; but I don't know how to make it listen to only the enter key.</p>
  <p>I have tried looking t other questions on Stackoverflow (notably <a href="https://stackoverflow.com/questions/155188/trigger-a-button-click-with-javascript-on-the-enter-key-in-a-text-box">here</a>), but my code editor is saying those notations are deprecated.</p>