duplicate row link

I have a form that includes a table.  I would like to have an "add" link to add another row if the user needs to input additional information. The name and id of the input field will need to change as the information is called in a function.  
<tr>
<td>Column 1</td>
<td><Name(s) <input name="n1" type="text" id="n1" onFocus="updateTA();" onBlur="updateTA();"><a href="add row">add person</a></td>
</tr>
rayne101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
The dynamically added rows have id "row1", "row2", etc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript"><!--	
var idList=1;
function addRow()
{
	
	var copy = document.getElementById("row0").cloneNode(true);
	copy.id = "row" + idList;
	++idList;
	document.getElementById("tbodyContainer").appendChild(copy);
}
//--></script>
</head>
<body>
<table>
	<tbody id="tbodyContainer">
		<tr id="row0">
		<td>Column 1</td>
		<td><Name(s) <input name="n1" type="text" id="n1" onFocus="updateTA();" onBlur="updateTA();"><a href"#" title="add row" onclick="addRow(); return false;" style="color:blue;text-decoration:underline;">add person</a></td>
		</tr>
	</tbody>
</table>
</body>
</html>

Open in new window

0
LakioCommented:
Something like this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Lakio made this</title>
	<script>
	namesCount = 1
	function addNameRow(linkElm)
	{
		namesCount += 1;
		var newRow = document.getElementById('EE').insertRow(-1);
		newRow.insertCell(0).innerHTML='Column ' + namesCount;
		newRow.insertCell(1).innerHTML='Name(s) <input name="n' + namesCount + '" type="text" id="n' + namesCount + '" onFocus="updateTA();" onBlur="updateTA();" /><a href="#" onclick="addNameRow(this); return false">add person</a>';
		linkElm.parentNode.removeChild(linkElm); // deletes the link
	}
	</script>
</head>
<body>
<table>
	<tbody id="EE">
		<tr>
			<td>Column 1</td>
			<td>Name(s) <input name="n1" type="text" id="n1" onFocus="updateTA();" onBlur="updateTA();" /><a href="#" onclick="addNameRow(this); return false">add person</a></td>
		</tr>
	</tbody>
</table>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rayne101Author Commented:
Both solutions look good, but Lakio yours looks as if it is updating the text field's  name and id.  I would like to add on to this and will post an additional question for more points if you would like.

After the row has been added I need the additional rows to be called by my current function.

<script language="javascript">
function updateTA(){
      var n1field = document.getElementById("n1");
      if(n1Field.value != ""){
           string += " The field displays" + n1Field.value + ".";
      }      
}
</script>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.