I have several drop down lists on my page. Based on the selection of these drop downs, I would like to build resulting Json object that looks like this:
{"list":{"city":["1","2","3"],"businessName":["City1","AnotherCity"]}}
Dropdowns event here:
$(".chosen-select").each(function () {
$id = this.id;
$value = $(this).val();
});
Of course I would like this to be as generic as possible therefore I'm getting $id (which in my case is "city" and "businessName", however it may be different on another page.
$value = $(this).val();
is of course array of selected values ie: "["1","2","3"];
I've tried this but it's not what I want
var jsonObj = {
list: []
};
$(".chosen-select").each(function () {
$id = this.id;
$value = $(this).val();
var obj = {};
obj[$id] = $value;
jsonObj.list.push(obj);
});
which results in this:
{"list":[{"city":["2","3"]},{"businessName":["KrakVenue1","KrakVenue3"]}]}
and NOT what I want.
How would I do it? thanks
$symbol for variables that arejQuerycollections.