recuperer le resultat d'un champ
Bonjour,
Je débute en JS et j'essais de mettre sur pied un bon de commande qui me calcul et m'affiche un prix en fonction d'une promo existante ou non, une quantité rentrée et enfin un montant total.
J'ai crée 2 fonctions : 1 pour la partie ss total avec quantité et une autre pour le montant global
La premiere fonctionne, mais impossible d'afficher quelque chose avec la seconde
Pouvez vous m'aider? je suis coincée :cry:
Merci,
Voici les fonctions
Code:
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
|
<script type="text/javascript">
function calcul_prix(){
for(i=1;i<10;i++){
var qte=document.getElementById("qte"+i).value;
var prix=document.getElementById("prix"+i).value;
var promo=document.getElementById("promo"+i).value;
var prixTotal=0;
(promo=="--")? prixTotal=prix * qte: prixTotal=promo * qte;
document.getElementById("prix_total"+i).value=prixTotal;
}
}
function Total_Commande(){
var total1=document.getElementById('prixtotal1').value;
var total2=document.getElementById('prixtotal2').value;
var totalc= 0;
totalc= total1 + total2;
document.getElementById("total").value=totalc;
}
</script> |
La partie HTML
Code:
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
|
<form name="test">
<table>
<tr>
<td> Prix</td>
<td></td>
<td> Promo </td>
<td></td>
<td> Quantite</td>
<td></td>
<td> Prix total </td>
<td></td>
<td> Total Commande </td>
</tr>
<tr>
<td><input type="text" size="3" disabled="disabled" value="8" id="prix1" /></td>
<td></td>
<td><input type="text" size="3" disabled="disabled" value="--" id="promo1" /></td>
<td></td>
<td><input type="text" size="3" class="qte" id="qte1" value="0" onchange="javascript:calcul_prix();" /></td>
<td></td>
<td><input type="text" size="4" readonly="readonly" id="prix_total1" /></td>
<td></td>
</tr>
<tr>
<td><input type="text" size="3" disabled="disabled" value="5" id="prix2" /></td>
<td></td>
<td><input type="text" size="3" disabled="disabled" value="8" id="promo2" /></td>
<td></td>
<td><input type="text" size="3" class="qte" id="qte2" value="0" onchange="javascript:calcul_prix();" /></td>
<td></td>
<td><input type="text" size="4" readonly="readonly" id="prix_total2" /></td>
</tr>
<tr>
<td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td>
<td> </td>
<td><INPUT TYPE="button" value="Total" onClick="javascript:Total_Commande();" /></td>
<td><input type="text" size="6" readonly="readonly" id="total" /> </td>
</tr>
</table>
</form> |