IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

calcul formulaire html - javascript


Sujet :

JavaScript

  1. #1
    Membre à l'essai
    Inscrit en
    Septembre 2011
    Messages
    20
    Détails du profil
    Informations forums :
    Inscription : Septembre 2011
    Messages : 20
    Points : 12
    Points
    12
    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 : 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
    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>

  2. #2
    Membre régulier
    Homme Profil pro
    Consultant process engineer industrial
    Inscrit en
    Janvier 2010
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant process engineer industrial
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Janvier 2010
    Messages : 148
    Points : 93
    Points
    93
    Par défaut
    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 : 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
    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>

Discussions similaires

  1. Formulaire html javascript
    Par dragonxav72 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 17/03/2012, 21h30
  2. Validation d'un formulaire HTML en javascript
    Par AliJava dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 26/12/2007, 17h02
  3. javascript formulaire html
    Par jérémy1664 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 24/10/2007, 12h15
  4. javascript pour récuperer les valeurs d'un formulaire html
    Par BetterWorld dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 18/05/2007, 12h09
  5. Réponses: 3
    Dernier message: 01/03/2007, 09h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo