Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Jonathan Leon
Jonathan Leon
18,813 Points

My form works but wont take me to 404 page, it just takes me to the form page again, is it okay?

?

Jonathan Leon
Jonathan Leon
18,813 Points

// Problem: Hints are shown even when forms are valid // Solution: hide and show the hints when valid var $password = $("#password"); var $confirmpassword = $("#confirm_password");

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

// find out if password is valid

function isPasswordValid() {

return $password.val().length > 8 ;

}

function passwordEvent() {

if (isPasswordValid()) {

  //Hide hint if valid

$password.next().hide(); } else {

//else show hint 

$password.next().show(); } };

function arePasswordsMatching () {

return $password.val() === $confirmpassword.val() ; }

function confirmpasswordEvent() { // find out if password and confirmation match if (arePasswordsMatching()) { // hide hint if match $confirmpassword.next().hide(); } // else show hint else {

$confirmpassword.next().show();

}}

// when event happens on password input

$password.focus(passwordEvent).keyup(passwordEvent).focus(confirmpasswordEvent).keyup(confirmpasswordEvent).keyup(enableSubmitEvent);

// when event happens on confirmation

$confirmpassword.focus(confirmpasswordEvent).keyup(confirmpasswordEvent).keyup(enableSubmitEvent);

// if user can submit functions

function canSubmit() {

return isPasswordValid() && arePasswordsMatching();

}

// submit disable\enable

function enableSubmitEvent() {

$("#submit").prop("disabled" , !canSubmit());

}

enableSubmitEvent();

4 Answers

Pretty sure that's cool.. happens with me too

The same thing happened with me too.

SAME