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
| function ajoutLigne(){
var Cell;
var article = document.forms["formulaire"].article.value;
var qte = document.forms["formulaire"].qte.value;
var pu = document.forms["formulaire"].pu.value;
var tva = document.forms["formulaire"].tva.value;
var pht = parseInt(qte,10) * parseInt(pu,10)
var tableau = document.getElementById('tableau');
var ligne = tableau.insertRow(-1);
Cell = ligne.insertCell(0);
Cell.innerHTML = ligne.rowIndex;
Cell = ligne.insertCell(1);
Cell.innerHTML = article;
Cell = ligne.insertCell(2);
Cell.innerHTML = qte;
Cell = ligne.insertCell(3);
Cell.innerHTML = pu;
Cell = ligne.insertCell(4);
Cell.innerHTML = tva;
Cell = ligne.insertCell(5);
Cell.innerHTML = pht;
Cell = ligne.insertCell(6);
var x = parseInt( document.forms["formulaire"].pt.value ,10) + parseInt(pht , 10);
document.forms["formulaire"].pt.value = x ;
var bouton = document.createElement("input");
bouton.type = "button";
bouton.value = "Supprimer";
bouton.onclick = function(){suppression(ligne)};
Cell.appendChild(bouton);
document.forms["formulaire"].article.value = "";
document.forms["formulaire"].qte.value = "";
document.forms["formulaire"].pu.value = "";
document.forms["formulaire"].tva.value = "";
}
function suppression(ligne){
document.getElementById('tableau').deleteRow(ligne.rowIndex);
var tableau = document.getElementById('tableau');
var trs = tableau.rows;
var n = trs.length;
var i;
for (i=1; i<n; i++) {
trs[i].cells[0].innerHTML = trs[i].rowIndex;
}
} |
Partager