Pb calcul formulaire html

pierre_gomes Messages postés 10 Statut Membre -  
pierre_gomes Messages postés 10 Statut Membre -
Bonjour,

j'ai un problème de calcul dans un script : la première ligne me calcule bien le montant des cotisations mais j'ai un problème sur la seconde ligne ; pourriez-vous m'aider merci

voici le code :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>calcul_cotisations</title>
</head>
<body>
<form method="post" name="calcul_cotisations">
<table style="text-align: left; width: 1150px; height: 110px;"
border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td
style="width: 281px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Code
et catégories de salariés</small></td>
<td
style="width: 228px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Salaires<br>
 arrondis</small></td>
<td
style="width: 134px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Taux
en %</small></td>
<td
style="width: 302px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Cotisations
arrondies </small></td>
</tr>
<tr>
<td style="width: 281px; font-family: Arial;"><small>100
A RG cas général - accident du travail</small></td>
<td
style="text-align: center; width: 228px; font-family: Arial;"><small><input
id="base_at" onchange="somme();" value="0"
type="text"></small></td>
<td
style="width: 134px; font-family: Arial; text-align: center;"><small><input
id="at" onchange="somme();" value="2" type="text"></small></td>
<td
style="text-align: center; width: 302px; font-family: Arial;"><small><span><input
id="resultat" value="0" type="text"></span></small></td>
</tr>
<tr>
<td style="width: 281px; font-family: Arial;"><small>100
D RG cas général - base
déplafonnée</small></td>
<td style="font-family: Arial; text-align: center;"><small><input
id="base_cg" onchange="resultat_cg();" value="0"
type="text"></small></td>
<td
style="width: 134px; font-family: Arial; text-align: center;"><small><span><input
id="cg" onchange="resultat_cg();" value="21"
type="text"></span></small>
</td>
<td
style="text-align: center; width: 302px; font-family: Arial;"><small><span><input
id="resultat_cg" value="0" type="text"></span></small>
</td>
</tr>
<tr>
<td style="font-family: Arial;"><small>100 A
RG cas général - base plafonnée</small></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
</tr>
<tr>
<td style="font-family: Arial;"><small>236 D
FNAL sur totalité des salaires</small></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
</tr>
<tr>
<td style="font-family: Arial;"><small>260 D
CSG - CRDS Régime général</small></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
</tr>
<tr>
<td style="font-family: Arial;"><small>671 P
Réduction Fillon - base plafonnée</small></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
<td style="font-family: Arial;"></td>
</tr>
</tbody>
</table>
<br>
<table style="text-align: left; width: 1153px; height: 118px;"
border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="font-family: Arial; width: 325px;"><small>Salaires
versés le </small></td>
<td style="font-family: Arial; width: 187px;"><small><input
name="date_versement"></small></td>
<td style="font-family: Arial; width: 68px;"></td>
<td
style="background-color: rgb(226, 189, 255); font-family: Arial; width: 177px;"><small>Total
des cotisations</small></td>
<td
style="font-family: Arial; width: 358px; text-align: center; background-color: rgb(226, 189, 255);"><small><input
name="total_cotisations"></small></td>
</tr>
<tr>
<td style="font-family: Arial; width: 325px;"><small>Effectif
au dernier jour de la période</small></td>
<td style="font-family: Arial; width: 187px;"><small><input
name="effectif_fin_periode"></small></td>
<td style="font-family: Arial; width: 68px;"></td>
<td
style="background-color: rgb(226, 189, 255); font-family: Arial; width: 177px;"><small>Déduction</small></td>
<td
style="font-family: Arial; width: 358px; text-align: center; background-color: rgb(226, 189, 255);"><small><input
name="deduction"></small></td>
</tr>
<tr>
<td style="font-family: Arial; width: 325px;"><small>Effectif
remunéré pour la période</small></td>
<td style="font-family: Arial; width: 187px;"><small><input
name="effectif_remunere_fin"></small></td>
<td style="font-family: Arial; width: 68px;"></td>
<td
style="background-color: rgb(226, 189, 255); font-family: Arial; width: 177px;"><small>Montant
à payer</small></td>
<td
style="font-family: Arial; width: 358px; text-align: center; background-color: rgb(226, 189, 255);"><small><input
name="montant_a_payer"></small></td>
</tr>
<tr>
<td style="font-family: Arial; width: 325px;"></td>
<td style="font-family: Arial; width: 187px;"></td>
<td style="font-family: Arial; width: 68px;"></td>
<td style="font-family: Arial; width: 177px;"></td>
<td style="font-family: Arial; width: 358px;"></td>
</tr>
</tbody>
</table>
<br>
<table style="text-align: left; width: 1153px; height: 60px;"
border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td
style="width: 328px; font-family: Arial; text-align: center; background-color: rgb(226, 189, 255);"><small>Libellé
du compte bancaire</small></td>
<td colspan="4" rowspan="1"
style="width: 200px; font-family: Arial; text-align: center; background-color: rgb(226, 189, 255);"><small>RIB</small></td>
<td
style="width: 398px; font-family: Arial; text-align: center; background-color: rgb(226, 189, 255);"><small>Montant</small></td>
</tr>
<tr>
<td
style="width: 328px; font-family: Arial; text-align: center;"></td>
<td
style="width: 66px; font-family: Arial; text-align: center;"></td>
<td
style="width: 68px; font-family: Arial; text-align: center;"></td>
<td
style="width: 124px; font-family: Arial; text-align: center;"></td>
<td
style="width: 200px; font-family: Arial; text-align: center;"></td>
<td
style="width: 398px; font-family: Arial; text-align: center;"></td>
</tr>
</tbody>
</table>
<br ="">
<script type="text/javascript"> function somme() { var result = document.getElementById('resultat'); var value1 = document.getElementById('base_at').value; var value2 = (document.getElementById('at').value); if (testInt(value1) && testInt(value2)) { result.value = parseInt(value1) * parseInt(value2) ; } else { alert('Les valeurs introduites ne sont pas des nombres'); } } function testInt(value) { return value == parseInt(value); } </script></form>
<script type="text/javascript"> function resultat_cg() { var resultat_cg = document.getElementById('resultat_cg'); var value3 = document.getElementById('base_cg').value; var value4 = (document.getElementById('cg').value); if (testInt(value3) && testInt(value4)) { resultat_cg.value = parseInt(value3) * parseInt(value4) ; } else { alert('Les valeurs introduites ne sont pas des nombres'); } } function testInt(value) { return value == parseInt(value); } </script>
</body>
</html>

6 réponses

  1. julius armoricanus
     
    Bonjour,
    Bizarre ton calcul? Par exemple si je fais ce test :
    Salaires arrondis = 800
    Taux en % = 2

    ça me donne :
    Cotisations arrondies = 1600

    Tu ne calcules donc pas sur un pourcentage mais tu fais une multiplication par 2 !!!!
    Il y a certainement un truc que je n'ai pas compris... ou bien c'est toi qui t'exprime mal?
    0
  2. pierre_gomes Messages postés 10 Statut Membre
     
    oui, je me suis mal exprimé : je veux simplement faire la multiplication des 2 nombres (le nom de la colonne ne va pas) mais je souhaiterais avoir de l'aide pour la seconde ligne qui ne fonctionne pas, savez vous pourquoi ?

    Merci
    0
    1. julius armoricanus
       
      Pourquoi tu ne fais pas tout dans la même fonction?
      <script type="text/javascript">
      function testInt(value) {
      	return value == parseInt(value);
      }
      function somme() {
      	var result = document.getElementById('resultat');
      	var resultat = document.getElementById('resultat_cg');
      
      	var value1 = document.getElementById('base_at').value;
      	var value2 = (document.getElementById('at').value);
      	var value3 = document.getElementById('base_cg').value;
      	var value4 = document.getElementById('cg').value;
      
      	if (testInt(value1) && testInt(value2)) {
      		result.value = parseInt(value1) * parseInt(value2);
      	} else {
      		alert('Les valeurs introduites ne sont pas des nombres');
      	}
      
      	if (testInt(value3) && testInt(value4)) {
      		resultat.value = parseInt(value3) * parseInt(value4);
      	} else {
      		alert('Les valeurs introduites ne sont pas des nombres');
      	}
      }
      </script>
      0
  3. pierre_gomes Messages postés 10 Statut Membre
     
    Merci, cela fonctionne mais j'ai tout de même un pb : celui de la saisie de la seconde base (2ème ligne) ; le calcul ne se met pas à jour sur la seconde ligne (champ : resultat_cg)

    autre question (si tu veux bien) : comment pourrais-je faire pour saisir un chiffre avec 2 décimales dans le champ at et cg ?

    merci
    0
    1. julius armoricanus
       
      </tr><tr>
      	<td style="width: 281px;">100 D RG cas général - base déplafonnée</td>
      	<td style="text-align: center;"><input id="base_cg" onchange="somme();" value="0" type="text" /></td>
      	<td style="width: 134px; text-align: center;"><input id="cg" onchange="somme();" value="21" type="text" /></td>
      	<td style="text-align: center; width: 302px;"><input id="resultat_cg" value="0" type="text" /></td>
      0
  4. pierre_gomes Messages postés 10 Statut Membre
     
    Sait-tu comment je peux :
    1) afficher 2 décimales dans les champs "taux"
    2) arrondir à l'entier le plus proche les montants arrondis

    Merci
    Pierre
    0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. pierre_gomes Messages postés 10 Statut Membre
     
    Excuse moi de nouveau : j'ai certainement supprimé et mes calculs ne fonctionnent plus ; pourrais tu regarder s'il te plait

    voici le code :

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1"
    http-equiv="content-type">
    <title>calcul_cotisations</title>
    </head>
    <body>
    <form method="post" name="calcul_cotisations">
    <table style="text-align: left; width: 1150px; height: 110px;"
    border="0" cellpadding="2" cellspacing="2">
    <tbody>
    <tr>
    <td
    style="width: 281px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Code
    et catégories de salariés</small></td>
    <td
    style="width: 228px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Salaires<br>
     arrondis</small></td>
    <td
    style="width: 134px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Taux
    en %</small></td>
    <td
    style="width: 302px; font-family: Arial; font-weight: bold; text-align: center; background-color: rgb(226, 189, 255);"><small>Cotisations
    arrondies </small></td>
    </tr>
    <tr>
    <td style="width: 281px; font-family: Arial;">100
    A RG cas général - accident du travail</td>
    <td
    style="text-align: center; width: 228px; font-family: Arial;"><small><input
    id="base_at" onchange="somme();" value="0"
    type="text"></small></td>
    <td
    style="width: 134px; font-family: Arial; text-align: center;"><small><input
    id="at" onchange="somme();" value="2" type="text"></small></td>
    <td
    style="text-align: center; width: 302px; font-family: Arial;"><small><span><input
    id="resultat" value="0" type="text"></span></small></td>
    </tr>
    <tr>
    </tr>
    <tr>
    <td style="width: 281px;">100 D RG cas
    général - base déplafonnée</td>
    <td style="text-align: center;"><input
    id="base_cg" onchange="somme();" value="0"
    type="text"></td>
    <td style="width: 134px; text-align: center;"><input
    id="cg" onchange="somme();" value="21" type="text"></td>
    <td style="text-align: center; width: 302px;"><input
    id="resultat_cg" value="0" type="text"></td>
    </tr>
    <tr>
    <td style="font-family: Arial;"><small>100 A
    RG cas général - base plafonnée</small></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    </tr>
    <tr>
    <td style="font-family: Arial;"><small>236 D
    FNAL sur totalité des salaires</small></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    </tr>
    <tr>
    <td style="font-family: Arial;"><small>260 D
    CSG - CRDS Régime général</small></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    </tr>
    <tr>
    <td style="font-family: Arial;"><small>671 P
    Réduction Fillon - base plafonnée</small></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    <td style="font-family: Arial;"></td>
    </tr>
    </tbody>
    </table>
    <br>
    <table style="text-align: left; width: 1153px; height: 118px;"
    border="0" cellpadding="2" cellspacing="2">
    <tbody>
    <tr>
    <td style="font-family: Arial; width: 325px;"><small>Salaires
    versés le </small></td>
    <td style="font-family: Arial; width: 187px;"><small><input
    name="date_versement"></small></td>
    <td style="font-family: Arial; width: 68px;"></td>
    <td
    style="background-color: rgb(226, 189, 255); font-family: Arial; width: 177px;"><small>Total
    des cotisations</small></td>
    <td
    style="font-family: Arial; width: 358px; text-align: center; background-color: rgb(226, 189, 255);"><small><input
    name="total_cotisations"></small></td>
    </tr>
    <tr>
    <td style="font-family: Arial; width: 325px;"><small>Effectif
    au dernier jour de la période</small></td>
    <td style="font-family: Arial; width: 187px;"><small><input
    name="effectif_fin_periode"></small></td>
    <td style="font-family: Arial; width: 68px;"></td>
    <td
    style="background-color: rgb(226, 189, 255); font-family: Arial; width: 177px;"><small>Déduction</small></td>
    <td
    style="font-family: Arial; width: 358px; text-align: center; background-color: rgb(226, 189, 255);"><small><input
    name="deduction"></small></td>
    </tr>
    <tr>
    <td style="font-family: Arial; width: 325px;"><small>Effectif
    remunéré pour la période</small></td>
    <td style="font-family: Arial; width: 187px;"><small><input
    name="effectif_remunere_fin"></small></td>
    <td style="font-family: Arial; width: 68px;"></td>
    <td
    style="background-color: rgb(226, 189, 255); font-family: Arial; width: 177px;"><small>Montant
    à payer</small></td>
    <td
    style="font-family: Arial; width: 358px; text-align: center; background-color: rgb(226, 189, 255);"><small><input
    name="montant_a_payer"></small></td>
    </tr>
    <tr>
    <td style="font-family: Arial; width: 325px;"></td>
    <td style="font-family: Arial; width: 187px;"></td>
    <td style="font-family: Arial; width: 68px;"></td>
    <td style="font-family: Arial; width: 177px;"></td>
    <td style="font-family: Arial; width: 358px;"></td>
    </tr>
    </tbody>
    </table>
    <br>
    <table style="text-align: left; width: 1153px; height: 60px;"
    border="0" cellpadding="2" cellspacing="2">
    <tbody>
    <tr>
    <td
    style="width: 328px; font-family: Arial; text-align: center; background-color: rgb(226, 189, 255);"><small>Libellé
    du compte bancaire</small></td>
    <td colspan="4" rowspan="1"
    style="width: 200px; font-family: Arial; text-align: center; background-color: rgb(226, 189, 255);"><small>RIB</small></td>
    <td
    style="width: 398px; font-family: Arial; text-align: center; background-color: rgb(226, 189, 255);"><small>Montant</small></td>
    </tr>
    <tr>
    <td
    style="width: 328px; font-family: Arial; text-align: center;"></td>
    <td
    style="width: 66px; font-family: Arial; text-align: center;"></td>
    <td
    style="width: 68px; font-family: Arial; text-align: center;"></td>
    <td
    style="width: 124px; font-family: Arial; text-align: center;"></td>
    <td
    style="width: 200px; font-family: Arial; text-align: center;"></td>
    <td
    style="width: 398px; font-family: Arial; text-align: center;"></td>
    </tr>
    </tbody>
    </table>
    <br ="">
    <script type="text/javascript">
    function testInt(value) {return value == parseInt(value);
    }
    function somme() {
    var result = document.getElementById('resultat');
    var resultat = document.getElementById('resultat_cg');
    var value1 = document.getElementById('base_at').value;
    var value2 = (document.getElementById('at').value);
    var value3 = document.getElementById('base_cg').value;
    var value4 = document.getElementById('cg').value;
    var value5 = document.getElementById('total_cotisations').value;
    if (testInt(value1) && testInt(value2)) {
    result.value = parseInt(value1) * parseInt(value2)/100;
    } else {
    alert('Les valeurs introduites ne sont pas des nombres');
    }
    if (testInt(value3) && testInt(value4)) {
    resultat.value = (parseInt(value3) * parseInt(value4))/100;
    } else {
    alert('Les valeurs introduites ne sont pas des nombres');
    }
    }
    </script></form>
    </body>
    </html>
    0
  7. pierre_gomes Messages postés 10 Statut Membre
     
    Ne pas tenir de mon dernier message, j'ai résolu le problème ; cependant, j'ai toujours mes 2 interrogations :
    1) afficher 2 décimales dans les champs "taux"
    2) arrondir à l'entier le plus proche les montants arrondis

    Merci beaucoup pour votre aide
    Pierre
    0