I have a table, which can contain arbitrarily many rows. Each of these rows holds an element of a form field. Initially, it looks like this:
<table border="2" id="familyHeader">
<tr>
<th>Description</th>
<th>Still associated?</th>
</tr>
<tr id="addNewChildRow">
<td>
<input type="text" ....>
<input type="text" ....>
</td>
<td>
<input type="submit" ....> <!-- this is intentionally not part of a form element -->
</td>
</tr>
<form id="family" method="post" action="php/update_children.php">
<tr id="updateChildrenRow">
<td> > > > > > > </td>
<td>
<input type="submit" id="updateChildren" name="updateChildren" class="updateChildren" value="Update Children"/>
</td>
</tr>
</form>
</table>
So basically the top part allows you to enter details - there is a capture on the first "submit" button which adds rows to the table. It adds them before the final row (so hopefully within the form element) using this JavaScript/jQuery:
function insert_child(id, type, snumber, serialnumber)
{
$('#updateChildrenRow').before("<tr> <td>"+ type+" | "+snumber+" | "+serialnumber +"</td>"
//$('#family').append("<tr> <td>"+ type+" | "+snumber+" | "+serialnumber +"</td>"
+ "<td> <input type=\"hidden\" name=\""+id+"\" value=\"false\" />"
+ "<input type=\"checkbox\" checked=\"true\" name=\""+id +"\" value=\"true\"/> </td>"
+ "</tr>");
}
This works, in that it inserts the element in the right place, but when we submit the form, the data is not POSTed. However, if we move the form element opening to the second line and submit, the "addNewChildRow" buttons are POSTed (which I presume shows my posting logic works, but it's just not detecting the dynamically added fields).
As you can see, I have tried appending to the form itself rather than the table, and this hasn't worked (they aren't displayed) - does anyone know what the trick is to dynamically add form elements to a table where they will be "detected" by the form which surrounds it?
Thanks :)
<form></form>style with nothing in it - only way I've found that works is moving the form element round the outside of the table - we're getting those two text fields, which is what I wanted to avoid - but it seems like the only way in this case - thanks for your help/pointers - if you write that as an answer I'll accept it :)