Bonjour,

J'ai besoin d'effectuer un calcul de tarifs dans mon formulaire (Chronoforms), avant de le soumettre.
J'ai tenté 2 manières, bouton "calculer" et "onchange" sur les input... rien de se passe.
J'ai 2 possibilités, soit je traite avec un individu, soit avec une entreprise (qui peut payer pour plusieurs individus).

Voici le script :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
function calculer(nb)
{
m=document.getElementById("totalInsc").value;
t=document.getElementById("tarif").value;
a=document.getElementById("ajtMontant").value;
d=document.getElementById("dedMontant").value);
m=(t+a-d)*nb;
}
et le 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
<table>
<tr>
<td><label class="cf_label" style="width: 100px;">Tarif de base</label></td>
<td><input class="cf_inputbox" maxlength="150" size="10" title="" id="tarif" name="tarif" type="text" value="<?php echo $row["tarif"]; ?>" /></td>
<td></td>
</tr>
<tr>
<td><label class="cf_label" style="width: 100px;">Compl&eacute;ments (+)</label></td>
<td><input class="cf_inputbox" maxlength="150" size="10" title="" id="ajtMontant" name="ajtMontant" type="text" value="0"/></td>
<td><input class="cf_inputbox" maxlength="150" size="20" title="" name="libAjtMontant" type="text" /></td>
</tr>
<tr>
<td><label class="cf_label" style="width: 100px;">D&eacute;ductions (-)</label></td>
<td> <input class="cf_inputbox" maxlength="150" size="10" title="" id="dedMontant" name="dedMontant" type="text" value="0" /></td>
<td><input class="cf_inputbox" maxlength="150" size="20" title="" name="libDedMontant" type="text" /></td>
</tr>
<?php if(!isset($_POST["idClient"])) {
?>
<!-- ceci s'affiche s'il s'agit d'un individuel -->
<tr>
<td><label class="cf_label" style="width: 100px;">Total</label></td>
<td><input class="cf_inputbox" maxlength="150" size="10" title="" id="totalInsc" name="totalInsc" type="text"  value="<?php echo $row["tarif"]; ?>"/></td>
<td><input value="Calculer" name="calculer" type="button" onclick="calculer(1)" /></td>
</tr>
<?php } else { ?>
<!-- ceci s'affiche s'il s'agit d'un client, susceptible de financer plusieurs individus -->
<tr>
<td><label class="cf_label" style="width: 100px;">Total</label></td>
<td><input class="cf_inputbox" maxlength="150" size="10" title="" id="totalInsc" name="totalInsc" type="text" value="<?php $tarif=$row["tarif"]*$nb; echo number_format($tarif, 2, '.', ' '); ?>"/></td>
<td><input value="Calculer" name="calculer" type="button" onclick="<?php echo 'calculer('.$nb.')';?>" /></td>
</tr>
<?php } ?>
</table>