Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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="{{ $item->id }}"data-id="{{ $item->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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, you are using the wrong selector. You should change .form-check in the javascript to .form-check-input or .delete-checkbox. Also you can easily get values of the selected checkboxes using jquery's .map() method.

Change your javascript code to something like this

function multiple_delete(id) {
    const selected = $(".delete-checkbox:checked").map((i, el) => el.value).get();

    if (selected.length > 0) {
        $.ajax({
            url: "multiple-delete",
            type: "POST",
            data: selected.join(","),
            success: function (data) {
                if (data["success"]) {
                    alert(data["success"]);
                } else {
                    alert(data["error"]);
                    console.log(data);
                }
            },
            error: function (data) {
                alert(data.responseText);
            },
        });
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!