Bonsoir à tous,
J'ai un problème dans un calcul réalisé avec des éléments dans un tableaux:
Tableaux HTML:
Ceci est un tableau html ou j'appelle une fonction javscript pour faire le calcul.
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 <table id="tabfourrage" ><tr><td ><u>Code Produit:</u></td><td ><u>Nom de la matiere:</u></td><td ><u>Fournisseurs:</u></td><td ><u>Quantite:</u></td><td ><u>Prix au KG:</u></td><td ><u>Pri de revient:</u></td></tr><tr> <td>77</td> <td>Abricots</td> <td>ALDIS</td> <td><input type="text" id="fourqte1" value="1.00 " size="5" onkeyup="calculTotal2(1)"></td> <td><input type="text" id="fourpu1" value="4.7310 " size="5" onkeyup="calculTotal2(1)"></td> <td><input type="text" id="fourmontant1" value="4.7310 " size="5" > € </td> </tr> <tr> <td rowspan="3"colspan="2"> Prix de revient au KG:<FONT COLOR="#FF0000"><b><input type="text" id="fourpdrakg" value="4.8276 " size="5" onkeyup="calculTotal2(1)"></b></font></td> <td> Poids Total mis en oeuvre:</td><td><input type="text" id="fourpoids" value="1.0000 " size="5" onkeyup="calculTotal2(1)"></b></font></td> <td rowspan="3"> TOTAL</td> <td rowspan="3"><input type="text" id="fourprix_f" value="4.7310 " size="5" >€</td> </tr> <tr> <td>Perte: <input type="text" id="fourperte_pdt" value="2.00 " size="5" onkeyup="calculTotal2(1)"></td> <td><input type="text" id="fouravantperte" value="0.0200 " size="5" onkeyup="calculTotal2(1)"></td> </tr> <tr> <td>Total Utilisable:</td><td><input type="text" id="fourtotal_utilisable" value="0.9800 " size="5" onkeyup="calculTotal2(1)"></td> </tr> <tr> <td>Poids Unitaire:<input type="text" id="fourpoids_u_f_pdt" value="0.1000 " size="5" onkeyup="calculTotal2(1)"></td> <td colspan="4" ALIGN="RIGHT"> Prix de revient matiere premiere unitaire</td> <td bgcolor="#FFA500" align=center><input type="text" id="fourprix_u_f" value="0.4828 " size="5" >€</td> </tr> </table>
Le problème c'est qu'il ne calcul pas le calcul total (fourprix_u_f) seulement quand il n'y a qu'une ligne.
(j'ai fait un autre essaie avec un tableau plus grand il calcul bien le total)
code javascript
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 function calculTotal2(pNum){ document.getElementById('fourmontant'+pNum).value = parseFloat(document.getElementById('fourpu'+pNum).value * document.getElementById('fourqte'+pNum).value); var nbLignes2 = document.getElementById("tabfourrage").rows.length - 5; document.getElementById('fourprix_f').value = 0; document.getElementById('fourpoids').value = 0; document.getElementById('fouravantperte').value = 0; for (a=1;a<=nbLignes2;a++) { var chaine_montant= "fourmontant"+a; var chaine_montant2= "fourqte"+a; document.getElementById('fourprix_f').value= parseFloat(document.getElementById('fourprix_f').value) + parseFloat(document.getElementById(chaine_montant).value); document.getElementById('fourpoids').value= parseFloat(document.getElementById('fourpoids').value) + parseFloat(document.getElementById(chaine_montant2).value); document.getElementById('fouravantperte').value= parseFloat(document.getElementById('fourpoids').value) / 100 * parseFloat(document.getElementById('fourperte_pdt').value); document.getElementById('fourtotal_utilisable').value= parseFloat(document.getElementById('fourpoids').value) - parseFloat(document.getElementById('fouravantperte').value); document.getElementById('fourpdrakg').value= parseFloat(document.getElementById('fourprix_f').value) / parseFloat(document.getElementById('fourtotal_utilisable').value); document.getElementById('fourprix_u_f').value= parseFloat(document.getElementById('fourpdrakg').value) * parseFloat(document.getElementById('fourpoids_u_f_pdt').value); document.getElementById('total_final').value= parseFloat(document.getElementById('prix_u_m').value) + parseFloat(document.getElementById('fourprix_u_f').value) + parseFloat(document.getElementById('pdr_emb').value) + parseFloat(document.getElementById('mpdr_m_o_u').value); }
Quel erreur j'ai pu commettre ?
Je problème est du a la longueur du tableau ou je met - 5. Non ?
Merci d'avance pour votre aide
guigui69
Partager