Bonjour,

Avis à tous les amateurs, j'ai besoin d'un coup de pouce.
Je suis en train de réaliser la création d'un panier très simple.
J'ai qu'un seul produit, mais je ne suis pas familier avec js).
J'ai 3 offres de frais de port (classique, colissimo, et chronopost).
Seulement à partir de 2 produit les frais de ports changent pour chaque type d'envoi...

J'ai "bidouillé" un script mais forcément ça déconne un peu (Le total ne fonctionne pas et ça ne marche que sous IE et pas FF). Je sens pourtant que j'y suis presque. Peut-être existe-t'il une méthode plus simple ?

Merci de vos lumières.

Voici un bout de la source.

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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
 
<script type="text/javascript">
<!--
var porttotal = 3.95;
 
 
function calculerPrix(champQte) {
	var champPrix = champQte.form.elements[champQte.name + "prix"];
	var champPrixUnite = champQte.form.elements[champQte.name + "unite"];
	//var	prixUnite = parseFloat(champPrixUnite.value);
	var	prixUnite = champPrixUnite.value;
	var qte = champQte.value;
	var champPort = f1.elements['port'];
	var champPort1 = f1.elements['port1'];
	var champPort2 = f1.elements['port2'];
	var champPort3 = f1.elements['port3'];
 
		if (qte == "") qte = 0;
		else if (isNaN(qte)) qte = 0;
		else qte = Math.floor(qte);
		if (qte < 0) qte = 0;
 
	if (qte>=2) port1=0; else port1=3.95;
	if (qte>=2) port2=2; else port2=5.95;
	if (qte>=2) port3=9; else port3=12.95;
 
	document.getElementById("port1").value=port1;
	document.getElementById("port2").value=port2;
	document.getElementById("port3").value=port3;
 
	var prix = prixUnite * qte;
	champPrix.value  = formatPrix(prix);
	calculerTotal(champQte.form);
}
 
 
function calculerTotal (form) {
	var champPort = form.elements['port'];
	var champTotal = form.elements['total'];
	//champPort.value	= formatPrix(port);
 
	if (champPort == 1)  { porttotal = port1; }
	if (champPort == 2)  { porttotal = port2; }
	if (champPort == 3)  { porttotal = port3; }	
 
	var total = 0;
		for (var i in form.elements) {
		if (
		//form.elements[i].name
		i.toLowerCase().indexOf("prix") != -1)
		total += parseFloat(form.elements[i].value);
		}
	//if (champPort == 1)  { total += port1; }
	//if (champPort == 2)  { total += port2; }
	//if (champPort == 3)  { total += port3; }			
	total += porttotal;
	champTotal.value = formatPrix(total);
}
 
function formatPrix (n) {
	n = Math.round(n*100)/100.0;
	var
	str = ""+n+"";
	var i = str.indexOf(".");
	if (i == -1) str += ".00";
	else if (i == str.length-2) str += "0";
	return str;
}
 
// -->
</script>
<form name="f1">
  <table cellpadding="5" width="100%">
<tr>  </tr>
<tr><td>Article</td><td>Quantité</td><td>Prix par unité</td><td>Prix selon
quantité</td></tr>
<tr>
	<td>Article 1 </td>
	<td>
		<select name="c1"  onchange="calculerPrix(this);" >
                  <option value="1" onChange="calculerPrix(this);" selected>1</option>
                  <option value="2" onChange="calculerPrix(this);">2</option>
                  <option value="3" onChange="calculerPrix(this);">3</option>
                  <option value="4" onChange="calculerPrix(this);">4</option>
                  <option value="5" onChange="calculerPrix(this);">5</option>
      </select>	
	</td>
<td> <input type="text" size="5" name="c1unite" value="64" /></td>
	<td> <input type="text" name="c1prix" size="5" value="64" /></td>
</tr>
<!--<tr><td>Frais
de port</td><td>&nbsp;</td><td>&nbsp;</td><td> <input type="text" name="port" value="6.95" size="5" /> </td></tr>
 
 <tr><td>TVA</td><td>&nbsp;</td><td>&nbsp;</td><td>
<input type="text" name="tva" value="0.00" size="5" /> </td></tr> -->
 
<tr>
  <td>TOTAL TTC (hors frais de livraison)</td><td>&nbsp;</td><td>&nbsp;</td><td> <input type="text" name="total" value="64" size="5" /> </td></tr>
<tr>  </tr>
<tr>
  <td>    Mode de livraison</td>
  <td colspan="2">D&eacute;lai de livraison </td>
  <td> Prix </td>
</tr>
<tr>
  <td> <input name="port" type="radio" value="1" onClick="calculerPrix(this);" checked>
    Livraison standard </td>
  <td colspan="2">5 &agrave; 10 jours ouvr&eacute;s</td>
  <td><input type="text" name="port1" value="3.95" size="5" /></td>
</tr>
<tr>
  <td> <input name="port" type="radio" value="2" onClick="calculerPrix(this);">
    Livraison colissimo suivi </td>
  <td colspan="2">3 &agrave; 5 jours ouvr&eacute;s </td>
  <td><input type="text" name="port2" value="5.95" size="5" /></td>
</tr>
<tr>
  <td><input name="port" type="radio" value="3" onClick="calculerPrix(this);">
    Livraison Express Chronopost </td>
  <td colspan="2">2 jours ouvr&eacute;s </td>
  <td><input type="text" name="port3" value="12.95" size="5" /></td>
</tr>
<tr>  </tr>
<tr>
  <td colspan="3" height="15">TOTAL TTC A REGLER</td>
  <td><input type="text" name="totalfinal" value="64" size="5" /></td>
</tr>
 
</table>
</form>