Bonjour,
J'ai un souci a faire la somme d'une colonne de x nombre de ligne...Voici le code de mon formulaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Document sans titre</title> <script language="javascript"> var index = 0; function loadData(valeur, indexLine) { var data ; var url = "ajax.php?reference=" + valeur; if(window.XMLHttpRequest) // FIREFOX xhr_object = new XMLHttpRequest(); else if(window.ActiveXObject) // IE xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); else return(false); xhr_object.open("GET", url, false); xhr_object.send(null); if(xhr_object.readyState == 4) { //alert(xhr_object.responseText); data = eval(xhr_object.responseText); document.getElementById("designation[" + indexLine + "]").value = data[1]; val_tarif=document.getElementById("tarif[" + indexLine + "]").value = data[2]; document.getElementById("colis[" + indexLine + "]").value = data[3]; document.getElementById("punet[" + indexLine + "]").value = data[2]; document.getElementById("total[" + indexLine + "]").value = data[2]; document.getElementById("montant_total").value = data[2]; } else return(false); } function calcul_remise(value,indexLine){ var val_tarif=document.getElementById("tarif[" + indexLine + "]").value var val_remise = document.getElementById("remise[" + indexLine + "]").value; val_punet = val_tarif - (val_tarif*val_remise*1/100); document.getElementById("punet[" + indexLine + "]").value = val_punet; var quantite = document.getElementById("quantite[" + indexLine + "]").value; var prix_total = quantite * val_punet; document.getElementById("total[" + indexLine + "]").value = prix_total; document.getElementById("montant_total").value = prix_total; //alert(val_tarif); } function calcul_quantite(value,indexLine){ var val_punet=document.getElementById("punet[" + indexLine + "]").value var quantite = document.getElementById("quantite[" + indexLine + "]").value; var prix_total = quantite * val_punet; document.getElementById("total[" + indexLine + "]").value = prix_total; //alert(val_tarif); } function addLine() { var newRow = document.getElementById('matable').insertRow(-1); var reference = newRow.insertCell(0); reference.innerHTML = '<input type="text" id="reference['+ index + ']" name="reference['+ index + ']" onChange="loadData(this.value, '+ index +')" />'; var designation = newRow.insertCell(1); designation.innerHTML = '<input type="text" id="designation['+ index + ']" name="designation['+ index + ']" readonly />'; var quantite = newRow.insertCell(2); quantite.innerHTML = '<input type="text" id="quantite['+ index + ']" name="quantite['+ index + ']" value="1" onChange="calcul_quantite(this.value, '+ index +')" OnKeyUp = "somme()" />'; var colis = newRow.insertCell(3); colis.innerHTML = '<input type="text" id="colis['+ index + ']" name="colis['+ index + ']" value="" />'; var remise = newRow.insertCell(4); remise.innerHTML = '<input type="text" id="remise['+ index + ']" name="remise['+ index + ']" value="" onChange="calcul_remise(this.value, '+ index +')" />'; var tarif = newRow.insertCell(5); tarif.innerHTML = '<input type="text" id="tarif['+ index + ']" name="tarif['+ index + ']" value="" readonly />'; var punet = newRow.insertCell(6); punet.innerHTML = '<input type="text" id="punet['+ index + ']" name="punet['+ index + ']" value="" />'; var total = newRow.insertCell(7); total.innerHTML = '<input type="text" id="total['+ index + ']" name="total['+ index + ']" value="" />'; index++; } function deleteLine() { var nb = document.getElementById('matable').rows.length; document.getElementById('matable').deleteRow(-1); } function somme(){ var n = index; //alert(n); while ( document.getElementById("total[" + n + "]") ) { //alert(document.getElementById("total[" + n + "]")); document.getElementById("montant_total").value= parseInt(document.getElementById("montant_total").value)+ parseInt(document.getElementById("total[" + n + "]").value); n++; } } </script> </head> <body> <form method="post" action="commande.php"> <table id="matable" width="1048" border="0"> <tr> <td width="111"><strong>REFERENCE</strong></td> <td width="131"><strong>DESIGNATION</strong></td> <td width="66"><strong>Quantité</strong></td> <td width="94"><strong>COLIS</strong></td> <td width="138"><strong>Remise(%)</strong></td> <td width="157"><strong>TARIF(FCFA)</strong></td> <td width="143"><strong>PU NET (FCFA)</strong></td> <td width="174"><strong>TOTAL (FCFA)</strong></td> </tr> </table> <table width="1367" id="matable2"> <tr> <td width="87"></td> <td width="103"></td> <td width="51"></td> <td width="73"></td> <td width="108"></td> <td width="124"></td> <td width="157"></td> <td width="291"></td> <td width="333"><strong>Montant Total:</strong><input type="text" id="montant_total" name="montont_total" value="" /></td> </tr> </table> <input type="button" name="button" id="button" value="Ajouter" onClick="addLine()" /> <input type="button" name="button3" id="button3" value="Supprimer" onClick="deleteLine()" /> <input type="submit" name="button2" id="button2" value="Valider" /> </form> </body> </html>
Partager