Salut,
Je suis depuis quelques jours sur ce tableaux a tenté d'en faire la somme. en javascript et je n'arrive pas.
j'ai essayé parsint +getelement getelement*1 etc mais rien.
Les lignes sont incrémentées en php (sur un BD mySQL)
et donc ca marche une fois sur deux et ca concatène les totals HT et TTC.
C'est un truc tout bête j'imagine
le JS est en bas.
Qu'en pensez-vous ?
Code php : 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 <h1><a href="Page.php">Paga</a></h1> <?php // LIGNES if (!ISSET($_SESSION['Lignes'])) { $_SESSION['Lignes'] = 2; // Ici le sql for($i=1; $i < $_SESSION['Lignes']; $i++) { // Declaration des sessions if (!ISSET($_SESSION['Designation'.$i])) {$_SESSION['Designation'.$i] = '';} if (!ISSET($_SESSION['Unite'.$i])) {$_SESSION['Unite'.$i] = '';} if (!ISSET($_SESSION['Prix'.$i])) {$_SESSION['Prix'.$i] = '';} if (!ISSET($_SESSION['Quantite'.$i])) {$_SESSION['Quantite'.$i] = '';} if (!ISSET($_SESSION['MontantHT'.$i])) {$_SESSION['MontantHT'.$i] = '';} } } echo '$_SESSION[= '. $_SESSION['Lignes'] . '<br>'; if (ISSET($_POST['Lignes'])) { // Ajouter ligne + declarer les variables $_SESSION['Lignes'] = $_SESSION['Lignes'] + $_POST['Lignes']; $nb_lignes_avant = $_SESSION['Lignes']; $nb_lignes_apres = $_SESSION['Lignes'] + $_POST['Lignes'] + 7; for($i=$nb_lignes_avant - 1; $i < $nb_lignes_apres; $i++) { // Sessions if (!ISSET($_SESSION['Designation'.$i])) {$_SESSION['Designation'.$i] = '';} if (!ISSET($_SESSION['Unite'.$i])) {$_SESSION['Unite'.$i] = '';} if (!ISSET($_SESSION['Prix'.$i])) {$_SESSION['Prix'.$i] = '';} if (!ISSET($_SESSION['Quantite'.$i])) {$_SESSION['Quantite'.$i] = '';} if (!ISSET($_SESSION['MontantHT'.$i])) {$_SESSION['MontantHT'.$i] = '';} } } echo '<p id="i">' . $i . "</p>"; ?> <form action="page.php" method="post" enctype="multipart/form-data" name="Form" style="font-size:21px "> <table id="tableau" style=" float:right; margin-right:121px" border="1"> <tr> <td class="Doc_Tableau" width="293" style="text-align:left; width:293px; "></td> <td class="Doc_Tableau" width="293" style="text-align:left; width:293px; ">Désignation</td> <td class="Doc_Tableau" width="89" style=" width:93px;" >Unité</td> <td class="Doc_Tableau" width="97" style=" width:93px;">Prix</td> <td class="Doc_Tableau" width="95" style=" width:95px;">Quantité</td> <td class="Doc_Tableau" width="119" style=" width:119px;">Montant HT </td> </tr> <?php for($i=1; $i < $_SESSION['Lignes']; $i++) { ?> <tr class="Doc_Tableau"> <td class="Doc_Tableau" style="text-align:left; width:293px; "> </td> <td class="Doc_Tableau" style="text-align:left; width:293px; "><?php echo "la " . $i;?> <select name="Designation<?php echo $i;?>" style="font-size:19px;"> <option <?php if ($_SESSION['Designation'.$i]== 'AAA') {echo 'AAA';}?>>AAA</option> </select> </td> <td class="Doc_Tableau" style=" width:93px;" ><input id="Unite<?php echo $i;?>" type="text" size="7" name="Unite<?php echo $i;?>" onChange="change_valeur(<?php echo $i;?>)" value="<?php if (ISSET($_SESSION['Unite'.$i])) {echo $_SESSION['Unite'.$i];} ?>" > </td> <td class="Doc_Tableau" style=" width:93px;"><input id="Prix<?php echo $i;?>" type="text" size="7" name="Prix<?php echo $i;?>" onChange="change_valeur(<?php echo $i;?>)" value="<?php if (ISSET($_SESSION['Prix'.$i])) {echo $_SESSION['Prix'.$i];} ?>" value="10" ></td> <td class="Doc_Tableau" style=" width:95px;"><input id="Quantite<?php echo $i;?>" type="text" size="7" name="Quantite<?php echo $i;?>" onChange="change_valeur(<?php echo $i;?>)" value="<?php if (ISSET($_SESSION['Quantite'.$i])) {echo $_SESSION['Quantite'.$i];} ?>" ></td> <!-- --> <td class="Doc_Tableau" style=" width:119px;"><input id="MontantHT<?php echo $i;?>" type="text" size="7" name="MontantHT<?php echo $i;?>" onChange="change_valeur(<?php echo $i;?>)" value="<?php if (ISSET($_SESSION['MontantHT'.$i])) {echo $_SESSION['MontantHT'.$i];}?>" ></td> </tr> <?php } ?> </table> <table style="float:right; margin-right:121px; text-align:center" border="0" align="right"> <tr> <td class="Doc_Tableau" style=" width:119px; text-align:right" >Total HT </td> <td class="Doc_Tableau" style=" width:119px;"><input type="text" size="7" id="TotalHT" ></td> </tr> <tr> <td class="Doc_Tableau" style=" width:119px; text-align:right" > Tva <select name="tva" style="font-size:19px;" id="TauxTva" onChange="change_Tva(<?php echo $i;?>)" > <option>20</option> <option>10</option> </select>% </td> <td class="Doc_Tableau" style=" width:119px;"><input type="text" size="7" id="MontantTVA" ></td> </tr> <tr> <td class="Doc_Tableau" style=" width:119px; text-align:right" >Montant TTC </td> <td class="Doc_Tableau" style=" width:119px;"><input type="text" size="7" id="TotalTTC" ></td> </tr> </table> <table id="tableau" style=" float:right; margin-right:121px" border="1"><tr><td> <h1 style="text-align:center "><input type="submit"></h1> </tr></td> </table> </form> <table id="tableau" style=" float:right; margin-right:121px" border="1"><tr><td> <form action="" method="post" >Lignes <input type="text" name="Lignes" value="1"><input type="submit"></form> </td></tr> </table>
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 var Total = 0; function change_Tva (){ document.getElementById('MontantTVA').value = document.getElementById('TotalHT').value * (document.getElementById('TauxTva').value/100); document.getElementById('TotalTTC').value = +document.getElementById('TotalHT').value + +document.getElementById('MontantTVA').value; } function change_valeur(valeur) { document.getElementById('MontantHT'+valeur).value = document.getElementById('Prix'+valeur).value * document.getElementById('Quantite'+valeur).value; var nb = '<?php echo $_SESSION['Lignes']; ?>'; var ligne = 1; while(ligne< nb) { document.getElementById('TotalHT').value = document.getElementById('MontantHT'+ligne).value ligne++; } alert('nb'+nb+'a'+ligne+' ligne'); document.getElementById('MontantTVA'). value = document.getElementById('TotalHT').value * (document.getElementById('TauxTva').value/100); document.getElementById('TotalTTC'). value = +document.getElementById('TotalHT').value + +document.getElementById('MontantTVA').value; }
Partager