lundi 21 mars 2022

Get value checkbox and push in array

Can you help me on how to get the checkbox values to be a data array? I code like this, and don't get any output. Thanks for helping me.

In my html :

<input class="form-check-input delete-checkbox" type="checkbox" name="checkbox[]" id="checkbox" value=""data-id="">

In my JS:

function multiple_delete(id) {
  const selected = [];
  $(".form-check input[type=checkbox]:checked").each(function () {
    selected.push(this.value);
  });
  if (selected.length > 0) {
    dataid = selected.join(",");
    $.ajax({
      url: "multiple-delete",
      type: "POST",
      data: +dataid,
      success: function (data) {
        if (data["success"]) {
          alert(data["success"]);
        } else {
          alert(data["error"]);
          console.log(data);
        }
      },
      error: function (data) {
        alert(data.responseText);
      },
    });
  }
}

My output :

console output




Aucun commentaire:

Enregistrer un commentaire