Hi,
I have that javascript to dynamically add rows to a table
function addNewRow(rowId)
{
var tbody = document.getElementById('item_list').tBodies[0];
var lastRow = tbody.rows.length - 1;
var rowId = lastRow;
var row = document.createElement('tr');
row.setAttribute('id', rowId);
..... (all the cells inserts)
tbody.appendChild(row);
return ++rowId;
and a button to add the row
<input type="hidden" name="rowId" id="rowId" value="">
<input class="button" type="button" onclick="rowId=addNewRow(rowId);" value="Add Another Row" />
First of all, when I remove the red, it does not work.
It does when I put it.
My problem is I also have another button to remove a row.
The method that I am using (counting the rows) does not work for me.
if I add 4 rows with id 1,2,3,4 then I remove rowId 3 for example, and then add another one, the count starts again and I end up getting id 1,2,4,4
How can I get the last ID so I don't have to use that bad method? And end up with id 1,2,4,5
Thank you.