The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Can't trigger button with ENTER key

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #271997

    Hello there.

    I’m new with javascript and was trying to make a simple password system that if correct would lead the user from the current page to a new one. I found this example online (can’t remember where, sorry) that works well but can’t add the “triggered by ENTER key” function to it. I was hoping someone could tell me what am I doing wrong. It’s probably something stupidly simple but I just can’t figure it out.

    This is the code so far:


    Give this a try…

        function checkPswd() {
          var confirmPassword = "";
          var password = document.getElementById("pswd").value;
          if (password == confirmPassword) {
            window.location = "welcome.html";
          } else {
            alert("Passwords do not match.");
        document.getElementById("pswd").addEventListener("keyup", function(event) {
          if (event.keyCode === 13) {
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.