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

Mike Capewell
Mike Capewell
4,501 Points

Website Waters 3 - Contact From Validation - containBlanks function

Hi Guys,

I'm working through the build-an-interactive-website module, and the stage: form-validation-and-manipulation.

For some reason I cannot get the following script to validate the form and enable to the submit button.

I think its the containsBlanks function but can't get to the button of it, really appreciate any help.

Thanks Mike

Code:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
var $submit = $(".submit input");
var $required = $(".required");

    function containsBlanks(){
        var blanks = new Array();
        $required.each(function(){
            blanks.push($(this).val() == "");
        });
        return blanks.sort().pop();
    }

    function isValidEmail(email){
        return email.indexOf("@") != -1;
    }

    function requiredFilledIn (){
        if(containsBlanks())
            $submit.attr("disabled","disabled");
        else
            $submit.remove.attr("disabled");
    }

    $("#form span").hide();
    $("input,textarea").focus(function(){
        $(this).next().fadeIn("slow");
    }).blur(function(){
        $(this).next().fadeOut("slow");
    }).keyup(function(){
        //Check all required fields.
    });

    $("#email").keyup(function(){
        // check for valid email.
        if(isValidEmail($(this).val()))
            $(this).next().removeClass("error").addClass("valid");
        else 
            $(this).next().removeClass("valid").addClass("error");
    });

    requiredFilledIn ();

</script>

4 Answers

James Barnett
James Barnett
39,199 Points

Mike Capewell - When posting issues with a code challenge make sure to post either the instructions or a link to the code challenge so we know what your code is trying to do.

Mike Capewell
Mike Capewell
4,501 Points

Sorry, it's not a code challenge, I following the steps here:

http://teamtreehouse.com/library/websites/build-an-interactive-website/form-validation-and-manipulation/checking-values

In form validation and can't seem to recreate the code correctly so the submit button enables when all fields are filled in correctly.

Thanks

Mike

Sorry to hear about the trouble you're having Mike. Is there any way you could email me directly at help@teamtreehouse.com? Mind sending a screenshot that includes your answer, Bummer! hint, and Code Challenge Task #? That would be super helpful. Thanks!

  • Elizabeth