Bonjour,
J'ai récupérer un bout de code javascript qui me permet de gérer un formulaire :
J'affiche les données du formulaire via un fichier javascript :
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
131
132
133
134 // TO DEFINE NEW PRODUCTS: arrayProducts= [ { "label":"Flyer", "page":"flyer.php" }, { "label":"Affiches", "page":"affiches.php" }, { "label":"Depliants", "page":"depliants.php" } ]; // DO NOT EDIT BELOW function productChanged() { var tt=document.getElementById("productID"); location.href=tt.options[tt.selectedIndex].value; } function composanteChanged() { var tt=document.getElementById("formatID"); // save selection var idxFormat=tt.selectedIndex; // re-init formats var data=arrayProductOptions[document.getElementById("composanteID").selectedIndex]["format"]; var i,n=data.length; if ((idxFormat>=n)||(idxFormat<0)) idxFormat=0; tt.options.length=n; for(i=0;i<n;i++) { tt.options[i]=new Option(data[i]["text"],data[i]["value"]); } tt.selectedIndex=idxFormat; formatChanged(); } function formatChanged() { // re-init impression var tt=document.getElementById("impressionID"); // save selection var idxImpression=tt.selectedIndex; // re-init impression var data=arrayProductOptions[document.getElementById("composanteID").selectedIndex]["format"][document.getElementById("formatID").selectedIndex]; document.getElementById("imageFormat").innerHTML=data["image"]; data=data["impression"]; var i,n=data.length; if ((idxImpression>=n)||(idxImpression<0)) idxImpression=0; tt.options.length=n; for(i=0;i<n;i++) { tt.options[i]=new Option(data[i]["text"],data[i]["value"]); } tt.selectedIndex=idxImpression; impressionChanged(); } function impressionChanged() { // re-init quantities var tt=document.getElementById("quantityID"); // save selection var idxQuantities=tt.selectedIndex; // re-init quantities var data=arrayProductOptions[document.getElementById("composanteID").selectedIndex]["format"] [document.getElementById("formatID").selectedIndex]["impression"] [document.getElementById("impressionID").selectedIndex]["quantity"]; var i,n=data.length; if ((idxQuantities>=n)||(idxQuantities<0)) idxQuantities=0; tt.options.length=n; for(i=0;i<n;i++) { tt.options[i]=new Option(data[i]["number"],data[i]["price"]); } tt.selectedIndex=idxQuantities; quantityChanged(); } function quantityChanged() { // update price var tt=document.getElementById("outputPrice"); var ttq=document.getElementById("quantityID"); tt.value=ttq.options[ttq.selectedIndex].value; } function pageInit(idxProduct) { // init products var tt=document.getElementById("productID"); var i,n=arrayProducts.length; tt.options.length=n; for(i=0;i<n;i++) { tt.options[i]=new Option(arrayProducts[i]["label"],arrayProducts[i]["page"]); } tt.selectedIndex=idxProduct; // init composantes var tt=document.getElementById("composanteID"); tt.options.length=0 var i,n=arrayProductOptions.length; for(i=0;i<n;i++) { tt.options[i]=new Option(arrayProductOptions[i]["text"],arrayProductOptions[i]["value"]); } tt.selectedIndex=0; composanteChanged(); // add listeners document.getElementById("productID").onchange=productChanged; document.getElementById("composanteID").onchange=composanteChanged; document.getElementById("formatID").onchange=formatChanged; document.getElementById("impressionID").onchange=impressionChanged; document.getElementById("quantityID").onchange=quantityChanged; }
A la récupération des données du formulaire en POST, la variable $_POST['quantity'] ne m'affiche pas la quantité mais le prix...
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 arrayProductOptions= [ { "value":"135gr", "text":"papier de 135gr", "format": [ { "value":"DIN A/6", "text":"DIN A/6", "image":"<image src='img_exemple/exemple_a6.jpg'/>", "impression": [ { "value":"Recto", "text":"Recto", "quantity": [ { "number":"1000", "price":"48" }, { "number":"2500", "price":"58" }, { "number":"5000", "price":"65" }, { "number":"10000", "price":"103" } ] }, { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"48" }, { "number":"2500", "price":"58" }, { "number":"5000", "price":"65" }, { "number":"10000", "price":"103" } ] } ] }, { "value":"DIN A/5", "text":"DIN A/5", "image":"<image src='img_exemple/exemple_a5.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"57" }, { "number":"2500", "price":"75" }, { "number":"5000", "price":"105" }, { "number":"10000", "price":"176" } ] } ] }, { "value":"DIN A/4", "text":"DIN A/4", "image":"<image src='img_exemple/exemple_a4.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"105" }, { "number":"2500", "price":"140" }, { "number":"5000", "price":"194" }, { "number":"10000", "price":"289" } ] } ] } ] }, { "value":"250gr", "text":"papier de 250gr", "format": [ { "value":"DIN A/6", "text":"DIN A/6 - 7.5x21 or 7.4x21 cm", "image":"<image src='img_exemple/exemple_a6.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"60" }, { "number":"2500", "price":"63" }, { "number":"5000", "price":"70" }, { "number":"10000", "price":"124" } ] } ] }, { "value":"DIN A/5", "text":"DIN A/5 - 14.8x21 cm", "image":"<image src='img_exemple/exemple_a5.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"85" }, { "number":"2500", "price":"107" }, { "number":"5000", "price":"136" }, { "number":"10000", "price":"240" } ] } ] }, { "value":"DIN A/4", "text":"DIN A/4 - 21x29.7 cm", "image":"<image src='img_exemple/exemple_a4.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"109" }, { "number":"2500", "price":"185" }, { "number":"5000", "price":"261" }, { "number":"10000", "price":"425" } ] } ] } ] }, { "value":"300gr", "text":"papier de 300gr + vernis", "format": [ { "value":"DIN A/6", "text":"DIN A/6 - 20.5x21 or 7.4x21 cm", "image":"<image src='img_exemple/exemple_a6.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"65" }, { "number":"2500", "price":"91" }, { "number":"5000", "price":"118" }, { "number":"10000", "price":"174" } ] } ] }, { "value":"DIN A/5", "text":"DIN A/5", "image":"<image src='img_exemple/exemple_a5.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"98" }, { "number":"2500", "price":"140" }, { "number":"5000", "price":"192" }, { "number":"10000", "price":"370" } ] } ] }, { "value":"DIN A/4", "text":"DIN A/4", "image":"<image src='img_exemple/exemple_a4.jpg'/>", "impression": [ { "value":"Recto/Verso", "text":"Recto/Verso", "quantity": [ { "number":"1000", "price":"150" }, { "number":"2500", "price":"257" }, { "number":"5000", "price":"352" }, { "number":"10000", "price":"690" } ] } ] } ] } ];
Merci d'avance
Voici mon formulaire :
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 <?php date_default_timezone_set('Europe/Paris'); ?> <html> <head> <script type='text/javascript' src='js/productFlyerOptions.js'></script> <script type='text/javascript' src='js/productSystem.js'></script> </head> <body> <form method="post" action="email.php" accept-charset="utf-8"> <table> <tr> <td>Produit</td> <td> <select name="product" id="productID"> </select> </td> <td rowspan="8" id="imageFormat"> <image src='image1.jpg'/> </td> </tr> <tr> <td>Composante</td> <td> <select name="composante" id="composanteID"> </select> </td> </tr> <tr> <td>Format</td> <td> <select name="format" id="formatID"> </select> </td> </tr> <tr> <td>Impression</td> <td> <select name="Impression" id="impressionID"> </select> </td> </tr> <tr> <td>Quantité</td> <td> <select name="quantity" id="quantityID"> </select> </td> </tr> <tr> <td colspan="2"> Price=<input type="text" name="price" id="outputPrice" value="-1" readonly="readonly" onFocus="document.getElementById('composanteID').focus();"/><br/><br/> <input name="submit" type="submit" value="Commander"> <input type="hidden" name="start" value="<?php echo time(); ?>" /> <input type="hidden" name="submitted" value="TRUE" /> </td> </tr> <table> </form> <script type='text/javascript'> window.onload=function(){ pageInit(0); } </script> </body> </html>
Partager