Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding duplicate rows to a table.

Status
Not open for further replies.

saroy71

Programmer
May 16, 2002
22
CA
I have a table that is a basic form with name address , etc. But it is possible for the person to have more than one address so I have a button that will duplicate all of the address information. Unfortunately I can't figure out how to duplicate the information but change the name of the input field.

So far I have:

function insertTableRow(id)
{
var table = document.getElementById(id);
// insert the new row
var newRow = table.insertRow();
rowHtml = table.rows(2).outerHTML;
rowAtr = rowHtml.split('>')[0].split(' ')
for(i=1;i<rowAtr.length;i++) {
rowAttribute = rowAtr.split('=')[0];
newRow.setAttribute(rowAttribute,table.rows(2).getAttribute(rowAttribute))
}
alert(newRow.outerHTML)
for (c=0; c<2; c++)
{
newCell = newRow.insertCell();
newCell.innerHTML = table.rows(2).cells(c).innerHTML;
}
}

Now say my last row in the table is:

<tr><td><input name=&quot;name&quot;></td></tr>

How do I duplicate the row BUT change the input name to name=&quot;name2&quot;??????

Any help is greatly appreciated. Education is what you get from reading the small print.
Experience is what you get from not reading it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top