[UPDATE]
Thanks guys,final code:
var EUR_share_cost = 0;
var USD_share_cost = 0;
var GBP_share_cost = 0;
var EUR_total_cost = 0;
var USD_total_cost = 0;
var GBP_total_cost = 0;
$.ajax({
url: '/producer/json/index/period/month/empties/'+empties+'/fields/'+fields+'/start/'+start+'/end/'+end+'',
async: false,
success: function(returned_values) {
$.each(returned_values.aaData, function(index, item) {
if (item[2] == 'EUR') {
EUR_share_cost += parseFloat(item[5]);
EUR_total_cost += parseFloat(item[3]);
} else if (item[2] == 'USD') {
USD_share_cost += parseFloat(item[5]);
USD_total_cost += parseFloat(item[3]);
} else if (item[2] == 'GBP') {
GBP_share_cost += parseFloat(item[5]);
GBP_total_cost += parseFloat(item[3]);
}
});
}
});
$('#EUR_share_cost').html(EUR_share_cost);
$('#USD_share_cost').html(USD_share_cost);
$('#GBP_share_cost').html(GBP_share_cost);
}
});
When you’re in
$.each(), the callback has 2 parameters, the first is the index (that incrementing number you’re seeing), the second is the actual item, you’d actually want something like this:I think overall you’re looking for this:
This would total up the third column…not sure which column you’re after (maybe 5th?), you can give it a try here.