Insert new row (rowspan) with Javascript

erydayNuaxy

New Member
I have Javascript like the following:\[code\]function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells.innerHTML; switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].valuehttp://stackoverflow.com/questions/14431537/= ""; break; } }}\[/code\]And HTML like the following:\[code\]<input type="button" value="http://stackoverflow.com/questions/14431537/Insert row" onclick="addRow('table1')" /><table id="table1" border=1> <tr> <td rowspan=2><input type="text" value="http://stackoverflow.com/questions/14431537/A"></td> <td><input type="text" value="http://stackoverflow.com/questions/14431537/A 1"></td> </tr> <tr> <td><input type="text" value="http://stackoverflow.com/questions/14431537/A 2"></td> </tr></table>\[/code\]I have a row with \[code\]rowspan=2\[/code\], and two rows with no rowspan. How do I write the following line so that once the user clicks the Insert Row button, three textboxes will be added into the new row?\[code\]newcell.innerHTML = table.rows[0].cells.innerHTML;\[/code\]
 
Back
Top