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 Build an Interactive Website Form Validation and Manipulation Checking Values

requiredValues Form validation task

Hey guys,

I'm having a hard time completing this form validation task. Although the first task (email) goes through the second one won't. Here is the code I came up with. Any suggestions?

Thanks

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

function requiredValues(){ //create a function called requiredValues
var $required = $(".required"); //define all inputs with a class of required
var storeArray = new Array();//create a new array where all input values will be stored
 $required.each(function(){//go through all inputs with a class of required
 storeArray.push($(this).val() =="");//and store their values in the new array
 return storeArray;//return the new array
 });

}
index.html
<!DOCTYPE html>
<html>
<head>
    <title>Modifying Attributes</title>
    <style type="text/css">
        .valid {
            color: green;
            border: 2px solid green;
        }
        .error {
            color: red;
            border: 2px solid red;
        }
    </style>
</head>
<body>

    <p>
        <input type="text" class="required" id="name" value="Andrew">
    </p>

    <p>
        <input type="text" class="required" id="company" value="Treehouse Island, Inc">
    </p>

    <p>
        <input type="text" class="" id="phone" value="555-123-4567">
    </p>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>