I have multiple checkboxes in form with values like this
<input type="checkbox" value="100400020719-006" name="selected" class="inforID" id="ABS-02072019" plant="VDNF" flowno="FLW-000001">
When checkbox is checked, and button is pressed, I will get attributes and insert into input with id arr
<input type="hidden" id="arr" name="arr" />
$(document).ready(function() {
$("#btnConf").click(function(){
var selected = [];
$.each($("input[name='selected']:checked"), function () {
selected.push($(this).val(), $(this).attr("id"), $(this).attr("plant"), $(this).attr("flowno"));
document.getElementById("arr").value = selected;
});
console.log(selected);
});
});
But the array which I get is
<input type="hidden" id="arr" name="arr" value="100400020719-006,ABS-02072019,VDNF,FLW-000001,100400020719-007,ABS-02072019,VDNF,FLW-000001">
How can I get the array like this:
[
{
"DocNo":"100400020719-006",
"NewDocNo":"ABS-02072019",
"Plant":"VDNF",
"FlowNow":"FLW-000001"
},
{
"DocNo":"100400020719-007",
"NewDocNo":"ABS-02072019",
"Plant":"VDNF",
"FlowNow":"FLW-000001"
}
]
Or like this
[
{
"100400020719-006",
"ABS-02072019",
"VDNF",
"FLW-000001"
},
{
"100400020719-007",
"ABS-02072019",
"VDNF",
"FLW-000001"
}
]
Thanks so much