Reputation: 1196
I have a really basic problem
$('#myForm').submit(function() {
var v= input_value(this,'validate_code');
alert(v);
}
function input_value(form, name){
var emptyFields = $(":input").filter(function() {
if(this.name == name) {
alert(this.value);
return this.value;
}
});
}
Why does alert(this.value)
show the real value and alert(v)
shows 'undefined' ?
Upvotes: 0
Views: 727
Reputation: 816424
The callback function you pass to filter
will not make the outer function input_value
return. The return statement inside the callback is only used to to decide whether to keep the element or not.
If you really want to get the empty fields, you would have to negate the value:
var emptyFields = $(":input").filter(function() {
return !this.value;
});
The question is, what do you want v
to be?
Upvotes: 1