Voilà le code Javascript qui fait un calcul sur chaque ligne du tableau généré par le code php.
Le code PHP :
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 <script language="Javascript"> function calculPrix() { for (var Nb=0;Nb<=100;Nb++) { var QTE = document.getElementById("quantite"+Nb ).value; var PU_HT = document.getElementById("prix_unitaire_ht"+Nb ).value; if( QTE !="" && PU_HT !="" ) { var TOTAL = document.getElementById("total_ht"+Nb ).value = (QTE * PU_HT).toFixed (2); return TOTAL; } } } </script>
Le problème c'est qu'il fait le calcul que sur la première ligne ou sinon si on commence par la dernière ligne et qu'on remonte jusqu’à la première sa marche. Mais si je remplie ligne par ligne a partir du début il ne fait le calcul que sur la première ligne... POURQUOI ?
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 <table id="table" align="center" BORDER="1" onchange="verifPrix()"> <tr align="center"> <th>Description</th><th>Qté</th><th>Prix Unitaire H.T</th><th>Total H.T</th> </tr> <?php for($compteur=0; $compteur<=$NbArt-1; $compteur++) { echo '<tr> <td><TEXTAREA name="description'.$compteur.'" id="description'.$compteur.'" rows=1 cols=40 ></TEXTAREA></td> <td><INPUT type="text" id="quantite'.$compteur.'" name="quantite'.$compteur.'" size="5" onchange="calculPrix()"></td> <td><INPUT type="text" id="prix_unitaire_ht'.$compteur.'" name="prix_unitaire_ht'.$compteur.'" size="8" onchange="calculPrix()"></td> <td><INPUT type="text" id="total_ht'.$compteur.'" name="total_ht'.$compteur.'" size="8" onchange="calculPrix()"></td> </tr>'; } ?> <tr> <td colspan="2" rowspan="4"></td> <td align="right"><strong>H.T</strong></td> <td><INPUT type="text" id="TotalHT" name="TotalHT" size="8" ></td> </tr> <tr> <td align="right"><strong>T.V.A 19,6%</strong></td> <td><INPUT type="text" name="nom" size="8"></td> </tr> <tr> <td align="right"><strong>PORT</strong></td> <td><INPUT type="text" name="nom" size="8"></td> </tr> <tr> <td align="right"><strong>TOTAL TTC</strong></td> <td><INPUT type="text" name="nom" size="8"></td> </tr> </table>
Merci a tous ceux qui essaye de comprendre !
Partager