bonsoir j'ai une page php qui affiche une liste de formulaires et dans chak formulaire on doit faire la multiplication de deux champs pour lafficher sur le 3éme voici mon code htlm
et voici le code 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 <?php if ($error == 0) { ?> <table width="30%" border="0" cellspacing="0" cellpadding="0" class="main" align="center"> <form name="getcountries" action="buy_number.php" method="post"> <input name="list" value="1" type="hidden"> <tr> <td colspan="3" align="center" class="theader"> </td> </tr> <tr> <td class="datatdh">Select country:</td> <td class="datatd"> <select name="co_id" onChange="this.form.submit();"> <option value="" selected>Select country</option> <?php for ($c =0; $c < count($result);$c++) { ?> <option value="<?php echo $result[$c]['country_id']; ?>" <?php if ($_POST['co_id'] == $result[$c]['country_id']) echo 'selected';?>><?php echo $result[$c]['country_prefix']." - ". $result[$c]['country_name']; ?></option>; <?php } ?> </select> </td> <td class="datatd"><input type="submit" class="bsubmit" name="list" value="List cities"></td> </tr> </form> </table> <br> <?php if ($error == 0 && count($result2) > 0) { ?> <table width="30%" border="0" cellspacing="0" cellpadding="0" class="main" align="center"> <tr> <td colspan="13" align="center" class="theader" nowrap> </td> </tr> <tr> <td class="datatdt" align="center">City prefix</td> <td class="datatdt" align="center">Cities</td> <td class="datatdt" align="center">Setup</td> <td class="datatdt" align="center">Monthly</td> <td class="datatdt" align="center">Periode</td> <td class="datatdt" align="center">Total Price</td> <td class="datatdt"> </td> </tr> <?php for($i=0; $i<count($result2); $i++){ ?> <form name=order action=order.php method=post > <tr> <td class="datatd" align="center" nowrap><?php echo $result2[$i]['city_prefix']; ?></td> <td class="datatd" align="center" nowrap><?php echo $result2[$i]['city_name']; ?></td> <td class="datatd" align="center" nowrap><input type="text" name="setup" value="<?php echo sprintf("%01.2f",5.00*1*1.43); ?>" size="5" readonly></td> <td class="datatd" align="center" nowrap><input type="text" name="monthly" value="<?php echo sprintf("%01.2f",$result2[$i]['monthly']*1*1.43); ?>" size="5" readonly></td> <td class="datatd" align="center" nowrap><select name="period" onChange="cal();"><option value="1">1</option> <option value="3">3</option> <option value="6">6</option> <option value="12">12</option> <option value="24">24</option> </select> </td> <td class="datatd" align="center" nowrap><input type="text" name="totalamount" value="<?php echo sprintf("%01.2f", ($result2[$i]['monthly']+5)*$currency*1.43); echo ' usd'; ?>" size="5" readonly></td> <td class="datatdt" align="center"> <input type="submit" style="width: 70px" name="order_did" value="Order DID"> </td> </tr> <input type="hidden" name="uniq" value="<?php echo $result2[$i]['uniq'];?>"> </form> <?php $_SESSION['uniq'] = $result2[$i]['uniq']; } ?> </table> <?php }} ?>
quant on fait un select du nombre de période ca doit calculer automatiquement le cout total pour une lign de la liste.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 function cal() { var pl=document.this.form.period.value; var set=document.this.form.setup.value; var mon=document.this.form.monthly.value; var resultat=Math.round((set+mon)pl*100)/100 document.this.form.totalamount.value=resultat; }
Je l'ai déja fait pour un seul formulaire mais pas encore pour une liste de formulaire.
Quelqu'un a-t-il une idée.Merci
Partager