var fields = ['firstName', 'lastName', 'address', 'postCode', 'email', 'phone', 'dob'];
for (var i=0; i<fields.length; i++) {
if (!$('#'+fields[i]).val()) {
alert('The ' + getFieldTitle(fields[i]) + ' field is required.');
return false;
}
values.fields[i] = $('#'+fields[i]).val();
console.log($('#'+fields[i]).val() , values , fields[i]);
}
Values is defined as a global variable at the beginning of the script. It seems that on the first iteration of assigning the proper name to the array position I get a failure. What i log the field names they appear to show up correctly but they don’t get assigned to the array values properly?
EDIT: Left out the fields initialization at first, sorry about that
If you want an object containing the id and value: