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

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,814 Points

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