I have a form, containing a table with rows of items for users to fill in. I currently have it set up so that the user can add an additional row in case they need to add more information.
This works wonderfully, but I'm wondering if there's a way to generate a unique id for each cloned field. My function is currently this: function addTableRow(table) { $(table).append($(table + ' tr:last').clone()); return true; } and is called from an onclick passing in the table id. The table row contains the following information: <tr> <td><input type="text" id="txtBarnParts1" name="txtBarnParts []"></td> <td><input type="text" id="txtBarnWidth1" name="txtBarnWidth []">ft</td> <td><input type="text" id="txtBarnRemarks1" name="txtBarnRemarks1[]"></td> </tr> What I would like is when I clone the row for the ids to be incremented by 1 so the next row would have ids: txtBarnParts2, txtBarnWidth2, txtBarnRemarks2...and so on. Is there a way to do this? Thanks!