Submit table values to database

Submit table values to database

andyHandyH Posts: 3Questions: 0Answers: 0
edited November 2009 in General
I have an table with the following structure :
[code]



Col1
Col2




row1col1
row2col2


...


rowncol1
rowncol2









[/code]

I edit the * value and I want to submit the new value thru an submit. So i have the code :

[code]
$('#example tbody td').editable( '../examples_support/editable_ajax.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
},
"height": "14px"
} );

$('#form').submit( function() {
var sData = $('input', oTable.fnGetNodes()).serialize();
return false;
} );
[/code]

How can I submit the edited values to an database when I press the submit button ?

Thank you.

Replies

  • andyHandyH Posts: 3Questions: 0Answers: 0
    In my example i dont want to serialize all the inputs from the table ... I want all the texts within TDs (row1col1, row1col2 , etc)

    I try to navigate thru the table structure as :

    [code]

    $('#form').submit( function() {
    var sData = oTable.fnGetNodes().serialize();
    var dd = sData.length;

    for(i=0;i<=dd;i++)
    {
    var rows = sData[i].childNodes;
    var cols = rows[1].childNodes;
    var af = cols[0].nodeValue;

    }
    return false;
    } );

    [/code]

    but it seems i do something wrong

    Can someone please help me on this.
  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin
    Hi andyH,

    Just to check my understanding - you want to send all of the data from the table - not just the form data? In which case, I think you'll need to use a bit more code then just 'serialize()' - which I believe only takes form elements and serialises them. You'll probably need to do a bit of a combination of DOM processing (to get the form elements) and using fnGetData() (or just keep doing DOM processing...) to construct an array of data to send, and then post that back to the server.

    Regards,
    Allan
  • andyHandyH Posts: 3Questions: 0Answers: 0
    Yes Allan ,

    Thats exactly what I intend ... but unfortunatelly I cannot access all the HTMLRowElements within the table.
    It seems I can access only the first column, and I dont find the second column.
    Do you know an algorithm or some code around to solve my problem ?

    Thanks.
  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin
    Hi andyH,

    There are probably lots of ways for doing this, but one method might be:

    1. Use fnGetNodes() to get all TR elements
    2. Loop over the columns (TD elements) from each row, and either get the data (innerHTML) or the form value are required
    3. Send the constructed 2D array.

    How does that sound?
    Allan
This discussion has been closed.