1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| <html>
<head>
<title>Dynamic table</title>
<script type="text/javascript">
function formatTable(dTable) {
var rows=dTable.rows;
}
function addRow() {
t=document.getElementById("table")
line=t.insertRow(t.rows.length)
cell=line.insertCell(0)
nr_line_crt=t.rows.length-1
cell.innerHTML=nr_line_crt
cell=line.insertCell(1)
cell.innerHTML="" + (t.rows.length)
formatTable(t)
cell=line.insertCell(2)
cell.innerHTML="<input name='ref' size='10' value=''><input name='addToCartsubmit' size='4'><input type=button VALUE='Supprimer' onClick='deleteRow(t.rows["+nr_line_crt+"].cells[0].innerHTML)'>"
}
function deleteRow(nr_line) {
// alert(nr_linie)
t=document.getElementById("table")
t.deleteRow(nr_line)
var line=t.rows;
for(var i=0;i<line.length;i++) {
line[i].cells[0].innerHTML=i
line[i].cells[2].innerHTML="<input name='ref' size='10' value=''><input name='addToCartsubmit' size='4'><input type=button VALUE='Supprimer' onClick='deleteRow(t.rows["+i+"].cells[0].innerHTML)'>"
}
}
</script>
</head>
<body>
<form>
<input type=button VALUE="Ajouter" onClick="addRow()">
<table id="table" border=0></table>
</form>
</body>
</html> |