Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
jmeckley said:I can't see writing js without a js library.
function hd_layer_duplicate ( source , target ) {
var duplicate = document.getElementbyId( source ).cloneNode(true);
var parent_node = document.getElementById( target );
parent_node.appendChild( duplicate );
}
function hd_layer_duplicate ( source , target ) {
var source_copy = document.getElementById( source ).cloneNode(true);
var target = document.getElementById( target ).parentNode;
target.appendChild( source_copy );
}
function addmyrow(mysource,mydest){
var tsource=document.getElementById(mysource);
var tdest=document.getElementById(mydest);
\\create new row
var mynewrow=tdest.insertRow(1);
\\create cells in row
var cell1=mynewrow.insertCell(0);
var cell2=mynewrow.insertCell(1);
var cell3=mynewrow.insertCell(2);
\\create the contents of the cells
cell1.innerHTML=tsource.cells[0].innerHTML;
cell2.innerHTML=tsource.cells[1].innerHTML;
cell3.innerHTML=tsource.cells[2].innerHTML;
}
[green]\\Get the table you wish to insert the row into[/green]
var mytable=document.getElementById('mytable');
[green]\\Insert Empty Row into table[/green]
var newrow=mytable.insertRow(1);
[green]\\get Row you wish to clone[/green]
var getrow=document.getElementById('mynewrow');
[green]\\Get number of cells to construct[/green]
var mycells=document.getElementById('mynewrow').cells.length-1;
[green]\\start loop to construct cells[/green]
for(var i=0;i<=mycells;i++){
[green]\\Create new cell[/green]
var newcell=newrow.insertCell(i);
[green]\\Copy cell contents to new cell[/green]
newcell.innerHTML=getrow.cells[i].innerHTML;
}
<html>
<head>
<script type="text/javascript">
var tableBody, rowToClone;
window.onload = function() {
tableBody = document.getElementById('myTable').tBodies[0];
rowToClone = tableBody.rows[0];
cloneRow('A new row', -1);
cloneRow('Another new row', -1);
cloneRow('New row inserted after first row', 1);
}
function cloneRow(textForFirstCell, newRowIndex) {
var newRow = rowToClone.cloneNode(true);
tableBody.appendChild(newRow);
// This must be doen AFTER adding the row to the table, otherwise the cells collection is not initialised
newRow.cells[0].innerHTML = textForFirstCell;
if (newRowIndex != -1) {
tableBody.insertBefore(newRow, tableBody.rows[newRowIndex]);
}
}
</script>
</head>
<body>
<table id="myTable" border="1" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td>Row 1</td>
<td><input type="text" value="Text" /></td>
<td><select><option>Select</option></select></td>
<td><input type="button" value="Button" /></td>
</tr>
</tbody>
</table>
</body>
</html>
<html>
<head>
<script src="jquery-1.3.2.min.js"></script>
<script>
$(function(){
$(":button").click(function(){
var copy = $(".copy").clone();
$(".copy").after(copy);
});
});
</script>
</head>
<body>
<table>
<tr>
<td>Row 1</td>
<td><input type="text" value="Text" /></td>
<td><select><option>Select</option></select></td>
<td><input type="button" value="Button" /></td>
</tr>
<tr class="copy">
<td>Row 2</td>
<td><input type="text" value="Text" /></td>
<td><select><option>Select</option></select></td>
<td><input type="button" value="Button" /></td>
</tr>
<tr>
<td>Row 3</td>
<td><input type="text" value="Text" /></td>
<td><select><option>Select</option></select></td>
<td><input type="button" value="Button" /></td>
</tr>
</table>
<input type="button" value="duplicate row 2" />
</body>
</html>