Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

What input type should I use for password form?

Hi, I'm trying to make a password form for my portfolio website. I'm having a problem with the input type.

When I have the input type as 'submit', typing password and hitting 'return' key will trigger the checkPswd() function. However, it does not link my website to 'index2.html'.

When I have the input type as 'button', the problem is the other way around. Now hitting 'return' key won't trigger the checkPswd(). However, it does link to 'index2.html' when I click on the submitubtton with mouse key.

I've also tried to trigger the checkPswd with (event.keyCode === 13), but it diddn't work. Does anybody have a solution?

    <div class="overlay_top">
          <div class="row justify-content-center" style="padding-top: 10%;">
                <form name="login">
                  <input type="password" id="pswd" class="form-control mx-sm-3" aria-describedby="passwordHelpInline" placeholder="Password" style="border-radius: 0rem; width:240px;">
                  <input type="submit" id="submitbutton" value="Submit" onclick=checkPswd() class="btn btn-white" style="border-radius: 0rem; width:240px; font-weight: 700;">
                </form>
          </div>
    </div>


    <script>
      function checkPswd() {
          var confirmPassword = "admin";
          var password = document.getElementById("pswd").value;
          if (password == confirmPassword) {
              window.location.href="index2.html";
          }
          else{
              alert("Passwords do not match.");
          }
      }
    </script>

1 Answer

  <input type="password" id="pswd" class="form-control mx-sm-3" ***aria****-describedby="passwordHelpInline" placeholder="Password" style="border-radius: 0rem; width:240px;">

Have you tried changing "aria" to "area"? I tried this in Codepen and it worked pretty well.