Checkbox data not being submitted, even when checked.

Checkbox data not being submitted, even when checked.

bezunarteabezunartea Posts: 2Questions: 1Answers: 0

Hi, I followed the instructions at https://editor.datatables.net/examples/api/checkbox.html but the value for the checkbox field is always '' (empty string). I debugged the following javascript in the browser and, this is what I saw:

...on("change", "input.editor-chosen", function() { var row = editor.edit($(this).closest('tr'), false); var chosen = $(this).prop( 'checked' ) ? 1 : 0; row.set('chosen', chosen); row.submit();

Even after the row.set() line, row.get('chosen') STILL returned '' (empty string).

Any ideas? TIA,

Pedro.

Answers

  • bezunarteabezunartea Posts: 2Questions: 1Answers: 0

    I solved the issue by sending a pure ajax GET request, because POST didn't submit anything. This is how I finally got it working: within the on "change" function:

        var tr = $(this).closest('tr');
        var row_data = table.row(tr).data();
        var is_selected = $(this).prop('checked') ? 1 : 0;
        var id = row_data['id'];
        var title = row_data['title'];
        $.ajax({
            type: 'GET',
            url: 'php/update-selected.php',
            data: { id: id, title: title, is_selected: is_selected },
            success: function(data) { 
                console.info('data: ' + data); 
            },
            failure: function(errMsg) {
                console.info('Error message: ' + errMsg);
            },
            contentType: "application/json",
            dataType: 'json'
        });
    

    The update-selected.php page just collects the data submitted, and deals with it.

    I still would like to know why it wouldn't post anything using the editor, and why POST doesn't submit anything, even using pure AJAX.

    Cheers,

    Pedro.

This discussion has been closed.