title: Trying to add a keydown event to a function
body: <p>I have been trying to add a keydown event to this function so that it not only submits the form when SUBMIT is clicked, but also when ENTER is pressed. My code and the code I want to add are below. I have tried to get the two to work together, but I'm confused about how to add the second code block. Oh, and validate() is being called from the HTML submit button element in the HTML file. Do I need to remove it from the HTML and create a brand new function that will perform both actions?</p>
  
  <p>Can anyone help, please and thank you?</p>
  
  <p>Here is my code: </p>
  
  <pre><code>function validate() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
  
    if (username == "abc" &amp;&amp; password == "123") {
      window.location = "http://www.google.com"; 
      return false;
    } else {
      alert("The user name or password is invalid.");
    }
  }
  </code></pre>
  
  <p>and here is the code I want to add: </p>
  
  <pre><code>function (event) {
      if (event.which == 13 || event.keyCode == 13) {
          //code to execute here
          return false;
      }
      return true;
  };
  </code></pre>