Forum de discussion
Forum « Programmation Javascript » (archives)
calcul dans un formulaire de commande
Envoyé: 3 mai 2004, 9h33 par mtbshoot
Que faire?
function AjouteVirgule(nombre)
{
var AvecVirgule = "";
var num = "" + Math.round(nombre*100);
if (num.length == 0) {AvecVirgule += "0.00";}
else if (num.length == 1) {AvecVirgule += "0.0" + num;}
else if (num.length == 2 && num > 0) {AvecVirgule += "0." + num;}
else if (num.length == 2 && num < 0) {AvecVirgule += "-"+Math.abs(num/100);}
else
{AvecVirgule += num.substring(0, num.length - 2);
AvecVirgule += ".";
AvecVirgule += num.substring(num.length - 2, num.length);}
return AvecVirgule;
}
function Calcule(form)
{
Selection = form.Article1.selectedIndex;
form.NomArticle1.value=form.Article1.options[Selection].text;
PrixArticle=form.Article1.options[Selection].value;
form.Prix1.value=AjouteVirgule(PrixArticle);
Selection = form.Quant1.selectedIndex;
Stotal1 = form.Quant1.options[Selection].value * form.Prix1.value;
form.Montant1.value = AjouteVirgule(Stotal1);
Selection = form.Article2.selectedIndex;
form.NomArticle2.value=form.Article2.options[Selection].text;
PrixArticle=form.Article2.options[Selection].value;
form.Prix2.value=AjouteVirgule(PrixArticle);
Selection = form.Quant2.selectedIndex;
Stotal2 =form.Quant2.options[Selection].value * form.Prix2.value;
form.Montant2.value = AjouteVirgule(Stotal2);
Selection = form.Article3.selectedIndex;
form.NomArticle3.value=form.Article3.options[Selection].text;
PrixArticle=form.Article3.options[Selection].value;
form.Prix3.value=AjouteVirgule(PrixArticle);
Selection = form.Quant3.selectedIndex;
Stotal3 = form.Quant3.options[Selection].value * form.Prix3.value;
form.Montant3.value = AjouteVirgule(Stotal3);
Selection = form.Article4.selectedIndex;
form.NomArticle4.value=form.Article4.options[Selection].text;
PrixArticle=form.Article4.options[Selection].value;
form.Prix4.value=AjouteVirgule(PrixArticle);
Selection = form.Quant4.selectedIndex;
Stotal4 = form.Quant4.options[Selection].value * form.Prix4.value;
form.Montant4.value = AjouteVirgule(Stotal4);
Selection = form.Article5.selectedIndex;
form.NomArticle5.value=form.Article5.options[Selection].text;
PrixArticle=form.Article5.options[Selection].value;
form.Prix5.value=AjouteVirgule(PrixArticle);
Selection = form.Quant5.selectedIndex;
Stotal5 = form.Quant5.options[Selection].value * form.Prix5.value;
form.Montant5.value = AjouteVirgule(Stotal5);
Selection = form.Article6.selectedIndex;
form.NomArticle6.value=form.Article6.options[Selection].text;
PrixArticle=form.Article6.options[Selection].value;
form.Prix6.value=AjouteVirgule(PrixArticle);
Selection = form.Quant6.selectedIndex;
Stotal6 = form.Quant6.options[Selection].value * form.Prix6.value;
form.Montant6.value = AjouteVirgule(Stotal6);
form.Montant1.value = AjouteVirgule(Stotal1);
form.Montant2.value = AjouteVirgule(Stotal2);
form.Montant3.value = AjouteVirgule(Stotal3);
form.Montant4.value = AjouteVirgule(Stotal4);
form.Montant5.value = AjouteVirgule(Stotal5);
form.Montant6.value = AjouteVirgule(Stotal6);
Total =(Stotal1+Stotal2+Stotal3+Stotal4+Stotal5+Stotal6);
MontantEuro=Total;
form.SousTotal.value = AjouteVirgule(Total);
form.MontantTotal.value = AjouteVirgule(Total);
form.MontantTotalEuro.value = AjouteVirgule(MontantEuro);
form.fraisdexp.value = AjouteVirgule(fraisdexp);
document.form.SousTotal.value = qtt;
var fraisdexp;
if (SousTotal>1){
fraisdexp = 2.60}
if (SousTotal>15){
fraisdexp = 0}
form.fraisdexp.value = fraisdexp;
// calcul du prix a payer en euros
var MontantTotal = SousTotal + fraisdexp;
}
<body>
<TR>
<TD class=line colspan="4"> <div align="right"><b>
Frais d'expeditions</b></div></td>
<TD class=line align="center"> <div align="center">
<input onchange=Calcule(this.form) type="text" name="fraisdexp" size="6">
€ </div></td>
</TR>
Réponses
|