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

Brice Roberts
Brice Roberts
22,415 Points

Would it not be simpler to call ".focusout()", instead of ".keyup"?

In the example in this lesson, Chalkers uses "focus" to define the first event, and then ".keyup" to trigger the second event.

For a better UX, would it be best practice to bind the event that checks the password for 8 characters, after the user has clicked out of it, so that the button event wouldn't trigger while the user is still typing?

Jordan Hoover
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Hoover
Python Web Development Techdegree Graduate 59,268 Points

You mean reduce the two events to just one focusout event? I suppose that would depend on your preferences, but I think he was trying to show how multiple events could be bound/triggered.

Brice Roberts
Brice Roberts
22,415 Points

Thank you. Yes, I guess I didn't clarify as well I should have. I knew the exercise is just proof of concept, so it was more of an internal problem solving question.

I wasn't sure if there was a real world benefit to splitting the event as shown.

2 Answers

Steven Parker
Steven Parker
231,275 Points

I think the whole point is to trigger during typing to give the user immediate feedback once the criteria have been satisfied (or if a change causes them to not be again).

Brice Roberts
Brice Roberts
22,415 Points

Yeah. I was just brainstorming other ways to complete the task. His is pretty straight forward, I was just trying to think outside the example.

Adrien Contee
Adrien Contee
4,875 Points

True you could use the focusOut() method but if the user went back and continued typing even passed 8 characters the pop up would still be visible... you would still need to bind a key up event. I think AC wanted to display how statement chaining could be used on events and I'm pretty sure AC will introduce the on() method really soon if not in the next video. But that's what i used.

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

$("#password").on("focus keyup", passwordCheck);

function passwordCheck() {
   if ($(this).val().length > 8) {
      $(this).next().hide();
   } else {
      $(this).next().show();
   }
}