i was searching on the web and stack but i cant found a way to solve my problem
so I hope someone can help me
i have a multi check box with same name “shopitem[]” and i want to check if check box are checked then send them value as array like “1,3,5,7” to php code with ajax
herere is my code:
<form id="ShopItemForm" class="ShopItemForm" method="post" name="ShopItemForm">
<input class="ShopItem" checked="checked" name="ShopeItem[]" id="1" value="1" type="checkbox">1
<input class="ShopItem" name="ShopeItem[]" id="2" value="2" type="checkbox">2
<input class="ShopItem" checked="checked" name="ShopeItem[]" id="3" value="3" type="checkbox">3
<input class="ShopItem" name="ShopeItem[]" id="4" value="4" type="checkbox">4
<input class="ShopItem" name="ShopeItem[]" id="5" value="5" type="checkbox">5
<input name="submitShopItem" value="submit" class="button button-push" id="submitShopItem" type="submit">
</form>
$(function() {
$("#submitShopItem").click(function(e) {
e.preventDefault();
// put all checked box to array checkedArray
var shopItem =
$("#shop-item-Loader").html('');
$("#shop-item-Loader").html('load');
$.ajax({
type: "POST",
url: "checked.php",
data: "act=shopItem&ShopItem="+checkedArray,
cache: false,
success: function(html){
alert(checkedArray);
$("#shop-item-Loader").html('');
$("#shop-item-Loader").append(html);
}
});
});
});
i want to send all new checked value to ajax page like coma separated string
Example
Edit
As suggested by @DavidThomas and the last sentence of the question:
To get a comma separated string of the checked elements you have to call
.join()oncheckedArrayWhen used like here
that’s done automatically