Skip to content Skip to sidebar Skip to footer

Submitting An Html Table Row To Php

I need help figuring out how to submit data from a table row into PHP to be processed. I would need it to be able to submit multiple rows of data. Any ideas? I have a table here. I

Solution 1:

$('#submit_btn').click(function(){
    var rows = [];
    $('#box-table-a tbody tr input[type=checkbox]:checked').each(function(i,v){
        var tds = $(v).parents('tr').children('td');
        rows.push({
            'name': tds.eq(1).find('select').val(),
            'units': tds.eq(2).text(),
            'calories': tds.eq(3).text(),
            'sugar': tds.eq(4).text()
        });
    });
    rows = JSON.stringify(rows); // submit this using $.post(...)
    $.post('classes/process.php', {'rows': rows}, function(data){
        console.log(data);
    });
});

submit rows using a $.post() and then, in the server side, you can convert back into an array using json_decode();

Sample output:

[{"name":"Water","units":"1","calories":"2","sugar":"3"},{"name":"Food","units":"4","calories":"5","sugar":"6"}]

Demo:http://jsfiddle.net/cp6ne/84/

Solution 2:

You could use the jQuery library to make an AJAX request to a PHP script that then 'processed' the data in the table.

You could also use the jQuery .each() function to perform this action on multiple rows.

Post a Comment for "Submitting An Html Table Row To Php"