Tom Tom - 1 month ago 10
jQuery Question

Serialize table tr data?

I'm serializing my form using :

formVals = $('#formID').serialize();


But I also have a table that I'd like to serialize and add it to
formVals
Can that be done? I've tried :

$('#tableName').find('tr').each(function(){
formVals = $(this).text().serialize();
})


But that results in


Uncaught TypeError: $(...).text(...).serialize is not a function


What I want to do is take the text from each
tr
and add it as a new entry to
formVals
along with the exiting date. Is there way to do this?

Thanks

UPDATE

A row looks like this :

<tr id="12354-515-asd">
<td>Today</td>
<td>0000</td>
<td>Monday</td>
<td>2345</td>
</tr>


The expected values to be added to formVals is:
12354-515-asd=Today0000Monday2345

Answer

You need to concatenate each parameter to formVals.

formVals = $("#formID").serialize();
$('#tableName').find('tr').each(function(){
    formVals += '&' + this.id + '=' + encodeURIComponent($(this).text());
});
Comments