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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| var columns=4,
lignes = 1,
arrayListe = new Array(lignes,columns);
function appendRow() {
var tbl = document.getElementById('tableHTML'), // table reference
row = tbl.insertRow(tbl.rows.length), // append table row
i;
// insert table cells to the new row
for (i = 0; i < tbl.rows[0].cells.length; i++) {
createCell(row.insertCell(i),'row');
}
lignes ++;
}
// create DIV element and append to the table cell
function createCell(cell, style) {
var div = document.createElement('div'); // create DIV element
var element6 = document.createElement("input");
element6.type = "text";
// create text node
div.appendChild(element6); // append text node to the DIV
div.setAttribute('class', style); // set DIV class attribute
div.setAttribute('className', style); // set DIV class attribute for IE (?!)
cell.appendChild(div); // append DIV to the table cell
}
// append column to the HTML table
function appendColumn() {
var tbl = document.getElementById('tableHTML'), // table reference
i;
// open loop for each row and append cell
for (i = 0; i < tbl.rows.length; i++) {
createCell(tbl.rows[i].insertCell(tbl.rows[i].cells.length), 'col');
}
columns ++;
}
// delete table rows with index greater then 0
function deleteRows() {
var tbl = document.getElementById('tableHTML'), // table reference
lastRow = tbl.rows.length - 1, // set the last row index
i;
// delete rows with index greater then 0
//for (i = lastRow; i > 0; i--) {
if(lastRow != 0) {
// table.deleteRow(i);
// rowCount--;
// i--;
// }
tbl.deleteRow(lastRow);
lignes --;
}
//}
}
// delete table columns with index greater then 0
function deleteColumns() {
var tbl = document.getElementById('tableHTML'), // table reference
lastCol = tbl.rows[0].cells.length - 1, // set the last column index
i, j;
// delete cells with index greater then 0 (for each row)
for (i = 0; i < tbl.rows.length; i++) {
// for (j = lastCol; j > 0; j--) {
if(lastCol != 2){
tbl.rows[i].deleteCell(lastCol);
columns --;
}
// }
}
}
function getValueTable(form){
for(i=0 ; i< lignes; i++){
var table = document.getElementById('tableHTML'),
k=0;
for(i=0 ; i< lignes; i++){
trs = table.getElementsByTagName('tr')[i];
for(j=0 ; j< columns; j++){
tds = trs.getElementsByTagName('td')[j],
// alert(tds.getElementsByTagName('input')[0].value);
arrayListe[k] = tds.getElementsByTagName('input')[0].value;
k++;
}
}
}
} |
Partager