Thanks. This is helpful and provides a good answer to my question.
What I am trying to do is a bit complicated beyond this. I have a table with rows that look like this:
<tr>
<input type="hidden" name="id_stakeholder[2]" value="76"><td> </td><td><input type="text" name="stakeholder[2]" value="Frank" style="width:100%" ></td><td><input type="text" name="phone[2]" value="510-171-1706" style="width:100%" ></td>
<td align="center" ><input type="checkbox" name="dem_data_[2][a]" value="Dem_data_checked" ></td>
<td align="center" ><input type="checkbox" name="dem_data_[2][b]" value="Dem_data_checked" ></td>
<td align="center" ><input type="checkbox" name="dem_data_[2][c]" value="Dem_data_checked" ></td>
<td align="center" ><input type="checkbox" name="dem_data_[2][d]" value="Dem_data_checked" ></td>
<td align="center" ><input type="checkbox" name="dem_data_[2][e]" value="Dem_data_checked" ></td>
<td align="center" ><input type="checkbox" name="dem_data_[2][f]" value="Dem_data_checked" ></td>
</tr>
It is a list of names, with several rows grouped by topic. I would like to let the user add rows at places in the table where there is a need for additional names. On submit, I am sending the post data to a php script and on to a database table. The rows and columns in the html table are identified by arrays generated from html name attributes with keys set as number and letter indexes by row and column.
When the new row is generated, I am going to have to provide a discrete index to the names in the row, so the information in the row can be entered into the database table as a discrete record.
I see this on sites, where one can add a new row by clicking, say, a “+” sign and a row appears. I have even done this myself using AJAX in simple forms where I was simply adding some html and I didn’t need to provide discrete naming data as I do here. I’m not very experienced with javascript and can imagine some kind of complex DOM function to modify elements within the row to which I need to assign specific information to generate a discrete record.
I’m wondering if anyone has seen a script designed to do something like this that I can modify, or at least learn from.
I’m also thinking of ways I can simplify the html/php interaction so the naming arrays are generated more automatically. The issue from a php scripting perspective is associating the various form input elements for each record with each other. For this reason, I am generating them from an incremented index variable so each element in a row has the same numeric index.
If a new row is inserted, I can utilize a numeric key that is way out of the range of what the script that generates the table will be using, say, starting with 1000. I will need to insert it into the content inserted by the javascript. I will also need to keep track of the new keys so if a user adds more that one row, keys are not duplicated.
I’m going at this step by step.
Thanks,
–Kenoli