Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript
JavaScript Forum programmation JavaScript. Lire : Cours JavaScript, FAQ JavaScript, Toutes les FAQ JavaScript et Sources JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 02/10/2011, 13h14   #1
Invité de passage
 
Inscription : septembre 2011
Messages : 14
Détails du profil
Informations forums :
Inscription : septembre 2011
Messages : 14
Points : 0
Points : 0
Par défaut calcul formulaire html - javascript

Bonjour

J'ai un formulaire en html où doit se calculer différentes lignes ; le premier calcul se fait correctement (fonction somme() en javascript)
mais la seconde ligne ne se calcul pas automatique (fonction resultat_cg() )
Pourriez-vous m'aider
merci
Pierre

voici le code :


Code html :
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
<!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&eacute;gories de salari&eacute;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>
&nbsp;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&eacute;n&eacute;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&eacute;n&eacute;ral - base
d&eacute;plafonn&eacute;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&eacute;n&eacute;ral - base plafonn&eacute;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&eacute; 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&eacute;gime g&eacute;n&eacute;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&eacute;duction Fillon - base plafonn&eacute;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&eacute;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&eacute;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&eacute;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&eacute;r&eacute; pour la p&eacute;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
&agrave; 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&eacute;
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>
  <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></form>
</body>
</html>
pierre_gomes est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/10/2011, 11h41   #2
Candidat au titre de Membre du Club
 
Inscription : janvier 2010
Messages : 52
Détails du profil
Informations forums :
Inscription : janvier 2010
Messages : 52
Points : 11
Points : 11
c'est ta fonction resultat qui ne fonctionné pas, je sais pas pourquoi tu avais changer value 1 et 2 ... seul chose que tu as a changer dans la fonction c'est l'ID de input et le nom de la fonction
Code :
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
 
<!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&eacute;gories de salari&eacute;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>
&nbsp;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&eacute;n&eacute;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&eacute;n&eacute;ral - base
d&eacute;plafonn&eacute;e</small></td>
        <td style="font-family: Arial; text-align: center;"><small>
        <input id="base_cg" onChange="sommes();" value="0" type="text"></small></td>
        <td
 style="width: 134px; font-family: Arial; text-align: center;"><small><span>
 <input id="cg" onChange="sommes();" 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&eacute;n&eacute;ral - base plafonn&eacute;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&eacute; 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&eacute;gime g&eacute;n&eacute;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&eacute;duction Fillon - base plafonn&eacute;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&eacute;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&eacute;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&eacute;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&eacute;r&eacute; pour la p&eacute;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
&agrave; 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&eacute;
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 sommes() { 
  var result = document.getElementById('resultat_cg'); 
  var value1 = document.getElementById('base_cg').value; 
  var value2 = (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'); } } 
  function testInt(value) { 
  return value == parseInt(value); } 
  </script></form>
</body>
</html>
djo007 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h55.


 
 
 
 
Partenaires

Hébergement Web