After you clone the elements, you must change (probably using an indentation) the name and the id of the form's elements.
Here's an example:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var clone;
function addRow(but){
var tbo=but.parentNode.parentNode.parentNode;
tbo.appendChild(clone);
var rows=tbo.getElementsByTagName('tr');
clone=rows[rows.length-1].cloneNode(true);
orderNames(rows)
}
function removeRow(but){
var thisRow=but.parentNode.parentNode;
var tbo=thisRow.parentNode;
tbo.removeChild(thisRow);
var rows=tbo.getElementsByTagName('tr');
orderNames(rows)
}
function orderNames(rows){
var i=0,r,j,inp,t,k;
while(r=rows[i++]){
inp=r.getElementsByTagName('input');j=0;k=1;
while(t=inp[j++]){
if(t.type=="text"){t.name='col_'+k+'_row_'+i;k++;}
}
}
}
onload=function(){
clone=document.getElementById('mytab').getElementsByTagName('tr')[0].cloneNode(true)
}
</script>
</head>
<body>
<form action="">
<table width="600" border="1" cellpadding="0" cellspacing="0" id="mytab">
<tr>
<td><input type="text" name="col_1_row_1"></td>
<td><input type="text" name="col_2_row_1"></td>
<td><input type="text" name="col_3_row_1"></td>
<td><input type="button" value="ADD NEW ROW" onclick="addRow(this)"><br><br>
<input type="button" value="REMOVE THIS ROW" onclick="removeRow(this)"></td>
</tr>
</table>
</form>
</body>
</html>
Bookmarks