Hi guys I got a tricky question for me.
I have this form in which i want them to combine into one array when i looped all the form fields that is located in a table header.
This is the loop i used to get all the data of the fields
$('#filterTable').find("table select, table input").each(function(key, value) {
var name = $(this).attr('name');
var input = {};
if (this.value !== ''){
if (name === 'filter_select') {
input.col = $(this).data('col');
input.layer_id = $(this).data('layer');
input.filterSelect = $(this).val();
} else if (name === 'froms'){
input.col = $(this).data('col');
input.layer_id = $(this).data('layer');
input.from = $(this).val();
} else if (name === 'to'){
input.col = $(this).data('col');
input.layer_id = $(this).data('layer');
input.to = $(this).val();
}
if(layerId == "" && input)
layerId = input.layer_id;
filterForm.push(input);
previous_col = $(this).data('col');
}
});
This code provide me the following output
0:
col: 2
layer_id: 139
from: "100"
1:
col: 2
layer_id: 139
to: "500"
what i want to accomplish is to combine them since they have the same col or they are located in the same table header so the output will look like this
0:
col: 2
layer_id: 139
from: "100"
to: "500"
any idea how can I solve this one? been stuck here for such a long time. Thanks