mardi 20 avril 2021

Get IDs of checkbox in jQuery and parse in PHP

We have a PHP page where we have multiple lines like this :

<tr><td><input type="checkbox" class="select_invoice" id="1"></td><td><span class="label label-info">TEST 1</span></td></tr>
<tr><td><input type="checkbox" class="select_invoice" id="2"></td><td><span class="label label-info">TEST2</span></td></tr>
<tr><td><input type="checkbox" class="select_invoice" id="3"></td><td><span class="label label-info">TEST 3</span></td></tr>
<tr><td><input type="checkbox" class="select_invoice" id="4"></td><td><span class="label label-info">TEST 4</span></td></tr>

We get the id via this jQuery function when we check one / multiple checkbox (#selected_download is a href button we show / hide if we have selected checkbox) :

$("#selected_download").hide();
$(".select_invoice").click(function(clicked_id) {
    if($('.select_invoice').is(":checked")) {
        $("#selected_download").show();
        var table_id = $('input[type=checkbox]:checked').map(function() {
        return this.id;
        }).get();
        console.log(table_id);
    } else {
        $("#selected_download").hide();
    }
});

The variable 'table_id' is an array of all IDs checked

How could we pass them to PHP ? We don't have any $_POST or form to send the array through AJAX.

Thanks and waiting you'r reply :)




Aucun commentaire:

Enregistrer un commentaire