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 Perfect

Tingting Gu
Tingting Gu
10,760 Points

Whether .keyup(enableSubmitEvent) is necessary

In the video, the .keyup(enableSubmitEvent is added at the end as follows:

$password.focus(passwordEvent).keyup(passwordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);  
$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

My question is that as we have already run "enableSubmitEvent();" at the end, why shall we still need to add ".keyup(enableSubmitEvent)"?

I think the enableSubmitEvent() will effect whether the key is gone up or not.

1 Answer

Hi Tingting,

The enableSubmitEvent() function is called once on page load. This is to essentially disable the submit button since all the inputs are blank when the page first loads.

That function is responsible for either enabling or disabling the submit button. So if you never call it again then you won't be able to enable the submit button.

The idea behind .keyup(enableSubmitEvent) is that as the user is typing you can repeatedly call that function to see whether the submit button should be enabled or not.

You don't know what keyup is finally going to be the one where all the validation passes so you call the enableSubmitEvent every time a key goes up.

Boris Baskovec
Boris Baskovec
4,798 Points

I think you could also add the disabled property directly in the HTML, so it's disabled by default

Marked as best answer