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.

JavaScript

Nicholas Llerandi
Nicholas Llerandi
4,936 Points

HTML Form / jQuery (beginner) Help

I'm trying to make a simple form where the submit button is not enabled until the username is > 5 characters. Any idea why this isn't working?

(first post - not really sure how to share code on here yet) https://w.trhou.se/3ey4i04g13

1 Answer

Hey Nicholas , I see your code and i found the problem why your code is not working

var $username = $('#username');
var $submit = $('#submit');

function isUsernameValid() {
    return $username.val().length > 5;
}

function enableSubmit() {
    $submit.prop('disabled', !isUsernameValid());
}

$username.focus(enableSubmit).keyup(enableSubmit);//you need to call the function each time when you focus or     releasing  key

hope it helps you

rydavim
rydavim
18,786 Points

I've changed your comment to an answer so that it may be voted on or marked as best answer.