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

CSS jQuery Basics (2014) Creating a Password Confirmation Form Perfect

Joe Consterdine
Joe Consterdine
13,965 Points

Why do you have to create multiple functions to enable/disable the form?

Why can't you do something like...

$submit = ("#submit");

$submit.click(function(){

if($password.val() === $confirmPassword.val()){ $submit.prop("enabled", true); } else { $submit.prop("disabled", false); } });

So when you click the submit button it checks if both the password and confirm password match... if they do the submit goes through and if not it doesn't.

Thanks Joe

1 Answer

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

The thing is, you need to be able to enable the submit button (in this case, anyway) only when the passwords match. To do that, you need to check after every keystroke, so the user knows that both passwords match and can hit submit at that point.

In addition, the 'click' method only fires when a button is clicked in an enabled state, so we must check the password fields and then decide to enable/disable the button with each keystroke depending on certain conditions (the passwords matching, in this case).