Pb calcul formulaire html

Fermé
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012 - 2 oct. 2011 à 11:38
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012 - 2 oct. 2011 à 15:10
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>
A voir également:

6 réponses

julius armoricanus
2 oct. 2011 à 13:32
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
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012
2 oct. 2011 à 13:41
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
julius armoricanus
2 oct. 2011 à 13:52
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
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012
2 oct. 2011 à 14:04
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
julius armoricanus
2 oct. 2011 à 14:10
</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
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012
2 oct. 2011 à 14:38
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

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012
2 oct. 2011 à 14:56
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
pierre_gomes Messages postés 9 Date d'inscription dimanche 2 octobre 2011 Statut Membre Dernière intervention 19 septembre 2012
2 oct. 2011 à 15:10
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