Like this? Firebug's giving me an error:
document.getElementById(tabid) is null
var root = document.getElementById(tab...ntsByTagName('tbody')[0]; //the root
Code:<!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" xml:lang="en" lang="en"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> /*<![CDATA[*/ function addRow(tabid){ var root = document.getElementById(tabid).getElementsByTagName('tbody')[0]; //the root var allRows = root.getElementsByTagName('tr');//the rows' collection var cRow = allRows[0].cloneNode(true)//the clone of the 1st row var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names) cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.length+1)) } var cSel = cRow.getElementsByTagName('select')[0]; cSel.setAttribute('name',cSel.getAttribute('name')+'_'+(allRows.length+1));//change the selecet's name root.appendChild(cRow);//appends the cloned row as a new row } function shownames(){ var allInp=document.getElementsByTagName('input'); for(var i=0;i<allInp.length;i++){ alert(allInp[i].name) } } /*]]>*/ </script> </head> <body> <form action="" method="get"> <table width="766" border="0" cellspacing="0" cellpadding="0" id="myTab"> <tr> <td width="191"><input type="text" name="textfield_a" /></td> <td width="191"><input type="text" name="textfield_b" /></td> <td width="98"><select name="select"> <option value="item1" selected="selected">item1</option> <option value="item2">item2</option> <option value="item3">item3</option> <option value="item4">item4</option> <option value="item5">item5</option> </select></td> <td width="286"></td> </tr> </table><br /> <input name="addARow" type="button" value="Add a Row" onclick="addRow('mytab1')"> <br /> <br /> <input name="submit" type="submit" value="Submit" /> <br /> <br /> <input name="button" type="button" onclick="shownames()" value="Show names"> </form> </body> </html>


Reply With Quote
Bookmarks