Skip to content Skip to sidebar Skip to footer

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 : $('#t

Solution 1:

You need to concatenate each parameter to formVals.

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

Solution 2:

The reason why you are getting the error "Uncaught TypeError: $(...).text(...).serialize is not a function" is because serialize() is not a function applicable to a "tr" or "td" element (you cannot do this):

http://api.jquery.com/serialize/

The .serialize() method creates a text string in standard URL-encoded notation. It can act on a jQuery object that has selected individual form controls, such as , , and : $( "input, textarea, select" ).serialize();

If you wish to append this data you need to build a string by fetching the ID of the table row, and then iterating through each <td> element (appending the data within) -- See Barmar's answer for a solid example.

Post a Comment for "Serialize Table Tr Data?"