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 trialBritt Danzer
19,539 PointsWhen 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
2 Answers
Erik Nuber
20,629 Pointsfunction 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.
Britt Danzer
19,539 Pointsok thank you!
Justin Iezzi
18,199 PointsCould 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.
Justin Iezzi
18,199 PointsJustin Iezzi
18,199 PointsHi 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!