Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Britt Danzer
Britt Danzer
19,539 Points

When I type a password in the password field greater than 8 characters the input disappears not the hint. Fix it.

What did I type wrong here?

//Problem: Hints are shown even when form is valid
//Solution: Hide and show them at appropriate times

//Hide hints
$("form span").hide();

function passwordEvent(){
    //Find out if password is valid  
    if($(this).val().length > 8) {
      //Hide hint if valid
      $("form span").hide();
    } else {
      //else show hint
      $("form span").next().show();
    }
}


//When event happens on password input
$("#password").focus(passwordEvent).keyup(passwordEvent);

//When event happens on confirmation input
  //Find out if password and confirmation match
    //Hide hint if match
    //else show hint

Hi Britt! I went ahead and formatted your post so that your code is easily readable. Check out the markdown cheatsheet located on this page to see how this is done. Thanks!

2 Answers

Erik Nuber
Erik Nuber
20,629 Points
function passwordEvent(){
    //Find out if password is valid  
    if($(this).val().length > 8) {
      //Hide hint if valid
      $("form span").hide();
    } else {
      //else show hint
      $("form span").next().show();
    }
}

Looks likes in here. You need to add in .next() to

 $("form span").next().hide();

edit: should explain as well not just fix it... It is looking at the given "form span" area of "this" currently, you are hiding that input instead of the .next() input which contains the hint itself. So that is why you are making the input disappear rather than the hint.

Could you post a workplace snapshot so we can see your HTML and CSS as well? I think your JavaScript is fine, and that the issue may stem from something else.