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

JavaScript jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 1

Cannot get hint/span elements to "hide" after putting in 9 characters.

I absolutely cannot figure this out. Everything works fine other than the span/hints will not hide after inputting 9 characters.

HTML: https://w.trhou.se/vn60uhy7jc

JS: https://w.trhou.se/vn60uhy7jc

Thanks!

2 Answers

rydavim
rydavim
18,814 Points

Looks like you're just not calling the function you wrote on keyup. Instead of having the keyup event call an anonymous function, try calling your passwordEvent function.

$("#password").focus(passwordEvent).keyup(passwordEvent);

The function you wrote works for me, you just need to activate it! Happy coding! :)

James N
James N
17,864 Points

Thanks! this helped me out alot!

Ian Friedel
Ian Friedel
11,960 Points

It looks like you are missing a few semi-colons on your passwordEvent function as well. And to follow up with rydavim once the event happens on password input you are creating the same function twice so by placing it one time as a separate variable then calling it when the event happens you can keep your code DRY.

I have the corrected code below to show the problem. I hope this helps or as well as I can figure it out so far. I am still a beginner so bare with my explanation.

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

function passwordEvent(){ if($(this).val().length > 8){ $(this).next().hide(); }else{ $(this).next().show(); }; /Missing semicolon/ }; /Missing semicolon/

//when event happens on password value $("#password").focus(passwordEvent).keyup(passwordEvent); /*Your just using the same variable from earlier instead of having to write out the function twice */

I hope this helps!