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
Jameson Nyeholt
Courses Plus Student 3,280 PointsForm Validation and Manipulation 2/3
I'm having trouble with 2/3. This is what I'm doing:
function isValidEmail(email){
return email.indexOf("@") != -1;
}
var $required = $('input.required[type="text"]');
function requiredValues() {
var Values = new Array();
$required.each(function(){
Values.push($required.val());
});
return Values();
}
4 Answers
Adam Soucie
Courses Plus Student 8,710 PointsJameson, I'm seeing two problems:
1.) Your selection for $required is overly specific. A simple $(".required") gives you inputs with the class ".required".
2.) You return statement is calling a undefined method. Drop the "()" and you'll be returning the actual array you created.
Andrew Chalkley
Treehouse Guest TeacherThanks for chiming in Adam :)
Patrick Bläsing
5,725 PointsHi, I still don´t get it right.... what do I wrong?
function requiredValues() {
var values = new Array();
$(".required").each(function(){
values.push($(".required").val());
});
return values;
};
// EDIT
GOT IT right now!
function requiredValues(){
var requiredValues = new Array();
$(".required").each(function() {
requiredValues.push($(this).val())
});
return requiredValues;
}
Andrew Chalkley
Treehouse Guest TeacherSpot on!
$(".required").val() is calling val() on all the .required at once. Whereas you need to call it on each of them, so, yep $(this).val() is correct!