I am trying to get values from checkboxes in the following format of an array. Maybe this is the simple problem for you guys but I am really stuck here.
This is my input types
<input type="checkbox" id="any" name="chk" value="value1">
<input type="checkbox" id="any1" name="chk" value="value2">
<input type="checkbox" id="any2" name="chk" value="value3">
<input type="checkbox" id="any3" name="chk" value="value4">
<input type="checkbox" id="any4" name="chk" value="value5">
jQuery code
var fuelType =new Array();
$.each($("input[name='chk']:checked"), function(){
console.log($(this).val())
fuelType.push($(this).val());
});
fuelType = fuelType.join(",");
console.log(fuelType);
I am getting following log
["value1,value2,value3",value4",value5"]
Required response
["value1","value2,"value3","value4","value5"]
Aucun commentaire:
Enregistrer un commentaire