I've put together a little javascript file which uses a clean framework, here's how it's formatted:
var functionLibrary = {
validateFields:function(inputArray, result) {
$.each(inputArray, function(index, listItem) {
if (!$.trim($("#" + listItem).val()).length) {
return "empty";
}
});
}
}
Here's me passing data to such function and getting an undefined when validating the response:
var Validation = functionLibrary.validateFields(['amount', 'ppemail']);
console.log(Validation);
Why does such function show undefined in the console log when it should be returning empty ?
validateFieldsis not returning anything... the each callback is returning the valueeachis not returning forvalidateFields. Try to put aconsole.logbefore the end ofvalidateFieldsto check if the function didn't return "empty" yet.