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 :

validation champs formulaire


Sujet :

JavaScript

  1. #1
    Membre régulier
    Profil pro
    Technicien Informatique
    Inscrit en
    Février 2006
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Technicien Informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 187
    Points : 89
    Points
    89
    Par défaut validation champs formulaire
    B onjour à tous !

    Je souahite effectuer un test sur les champs d'un formulaire
    Ou dois je placer le code pour que cela fonctionne mon code est il correct ?

    Merci d'avance pour vos conseils et explications

    Jean Marc



    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
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
     
    <script language="jscript">
    function control_classe() 
    { 
    if (document.form_ajout.nom_p.value==""); 
    { 
    alert("Veuillez saisir le nom de la personne"); 
    return false; 
    } 
    else 
    { 
    if (document.form_ajout.prenom_p.value=="") 
    { 
    alert("Veuillez saisir le prénom de la personne"); 
    return false; 
    } 
    else 
    { 
    return true; 
    } 
    } 
    }
    </script>             
    <form action="ajout.php" method="post" enctype="application/x-www-form-urlencoded" name="form_ajout" OnSubmit="return control_classe()">    
        <tr>
            <td height="21" colspan="2"><h1>Ajouter une personne</h1></td>
        </tr>
    </table>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td class="corps"><td height="56">
    <form action="ajouter.php" method="POST" name="form1" OnSubmit="return control_classe()">
        <br>
                <table  border="0" cellpadding="0" cellspacing="0" class="conteneur">
                  <tr valign="top">
                    <td width="50%"><table border="0" cellpadding="1" cellspacing="0" class="detailMaj" >
                        <tr>
                          <td colspan="2" class="titre">Identit&eacute;</td>
                        </tr>
                        <tr>
                          <td colspan="2" align="center" ><input type="radio" name="radiobutton" value="monsieur">
                            Mr&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="radiobutton" value="madame">
                            Mme&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="radiobutton" value="mademoiselle">
                            Mlle                        
                            <input name="id_civ" type="hidden" value="1"></td>
                        </tr>
                        <tr>
                          <th width="22%"><label for="nom">Nom</label></th>
                          <td width="78%"><input name="nom_p" type="text" class="input" size="30" maxlength="32" id="nom">
                              <span class="obligatoire">*</span></td>
                        </tr>
          <tr>
                          <th><label for="nomnaissance">Pr&eacute;nom(s)</label></th>
                          <td><input name="prenom_p" type="text" class="input" size="30" maxlength="32" id="prenom">
                           <span class="obligatoire">*</span> </td>
                        </tr>
                        <tr>
                          <th><label for="commune">Qualit&eacute;</label></th>
                          <td></label><span class="obligatoire">
                          <label>
           <? 
          echo("<select name='qualite' size='1' id='qual_id'>");
          while($data=mysql_fetch_array($resultat_qual)){
           $type=$data['type'];
           echo"<option value=\"$type\">$type.</option>";
           };
           ?>                     
                          </select>
                          </label>
                            </span></td>
                        </tr>
                        <tr>
                          <th colspan="2"><label for="qualite"><br>
                          </label></th>
                        </tr>
                        <tr>
                          <td colspan="2" class="titre">Adresse</td>
                        </tr>
                        <tr>
                          <td colspan="2" align="center" >&nbsp;</td>
                        </tr>
                        <tr>
                          <th><label for="rue">Rue</label></th>
                          <td><textarea name="nom_rue" cols="30" rows="3" class="input" id="nom"></textarea>
                              <span class="obligatoire">*</span></td>
                        </tr>
                        <tr>
                          <th><label for="code_postal">Code Postal</label></th>
                          <td><input name="cp_com" type="text" class="input" size="5" maxlength="5" id="CP">
                          <input name="com_id" type="hidden" value="12"></td>
                        </tr>
                        <tr>
                          <th><label for="ville">Ville</label></th>
                          <td><input name="nom_com" type="text" class="input" size="30" maxlength="32" id="ville"></td>
                        </tr>
                        <tr>
                          <th><label for="tel_p">T&eacute;l&eacute;phone</label></th>
                          <td><input type="text" name="tel_ref1" size="10" class="input" id="tel_p">
                            (Domicile) <span class="obligatoire">*</span></td>
                        </tr>
                        <tr>
                          <th colspan="2">&nbsp;</th>
                        </tr>
                        <tr>
                          <td colspan="2" class="titre">Association</td>
                        </tr>
                        <tr>
                          <th colspan="2">&nbsp;</th>
                        </tr>
                        <tr>
                          <th><label for="asso"></label></th>
                          <td>
                            <label></label><span class="obligatoire"><label>
                            <? 
          echo("<select name='asso_id' size='1' id='asso_id'>");
          while($data=mysql_fetch_array($resultat)){
           $type=$data['nom_a'];
           echo"<option value=\"$type\">$type.</option>";
           };
           
                             ?>
                              </select>
                          </label>
                          </span></td>
                        </tr>
                        <tr>
                          <th colspan="2">&nbsp;</th>
                        </tr>
                    </table></td>
                    <td width="50%"><table border="0" cellpadding="1" cellspacing="0" class="detailMaj" summary="Bloc Referents;">
                      <tr>
                        <td colspan="2" class="titre">R&eacute;f&eacute;rent(s) </td>
                      </tr>
                      <tr>
                        <th colspan="2">&nbsp;</th>
                      </tr>
                      <tr>
                        <th colspan="2"><div align="center">principal</div></th>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" ><input type="radio" name="radiobutton" value="radiobutton">
                          Mr&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mme&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mlle</td>
                      </tr>
                      <tr>
                        <th><label for="label5">Nom</label></th>
                        <td><input name="nom_ref1" type="text" class="input" size="30" maxlength="32" id="label5">
                            <span class="obligatoire">*</span></td>
                      </tr>
                      <tr>
                        <th><label for="label6">Pr&eacute;nom(s)</label></th>
                        <td><input name="Prenom_ref1" type="text" class="input" size="30" maxlength="32" id="label6">
                            <span class="obligatoire">*</span> </td>
                      </tr>
                      <tr>
                        <th><label for="label6">Fonction</label></th>
                        <td><label>
                            <? 
          echo("<select name='ref_id' size='1' id='ref_id'>");
          while($data=mysql_fetch_array($resultat_ref)){
           $type=$data['fonction'];
           echo"<option value=\"$type\">$type.</option>";
           };
           
                             ?>
         
         
         
         
         
                       
                            </select>
                            <span class="obligatoire">*</span></label></td>
                      </tr>
                      <tr>
                        <th><label for="label4">T&eacute;l&eacute;phone</label></th>
                        <td><input type="text" name="tel_ref1" size="10" class="input" id="label4">
                          (Domicile) 
                          <span class="obligatoire">*</span></td>
                      </tr>
                      <tr>
                        <th colspan="2">&nbsp;</th>
                      </tr>
                      <tr>
                        <th colspan="2"><div align="center">secondaire</div></th>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" ><input type="radio" name="radiobutton" value="radiobutton">
                          Mr&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mme&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mlle</td>
                      </tr>
                      <tr>
                        <th><label for="label7">Nom</label></th>
                        <td><input name="nomR2" type="text" class="input" size="30" maxlength="32" id="label7"></td>
                      </tr>
                      <tr>
                        <th><label for="label8">Pr&eacute;nom(s)</label></th>
                        <td><input name="prenomR2" type="text" class="input" size="30" maxlength="32" id="label8"></td>
                      </tr>
                      <tr>
                        <th><label for="label8">Fonction</label></th>
                        <td><input name="fonctionR2" type="text" class="input" size="30" maxlength="32" id="label8"></td>
                      </tr>
                      <tr>
                        <th><label for="label9">T&eacute;l&eacute;phone</label></th>
                        <td><input type="text" name="telR2" size="10" class="input" id="label9">
                          (Domicile) </td>
                      </tr>
                      <tr>
                        <th height="20" colspan="2">&nbsp;</th>
                      </tr>
                    </table></td>
                  </tr>
                </table>
                <table width="757" border="0" cellpadding="0" cellspacing="0" class="validation" summary="Zone de bouton : Suivant">
                  <tr>
                    <td height="24"><input name="enregistrer" type="submit" class="bouton" id="Submit" title="Bouton : enregistrer" value="enregistrer">
                    </td>
                  </tr>
                </table>                                                        
    </form>            
        
    <? include("./Templates/production_footer.dwt");?>
    Jean Marc

  2. #2
    Modérateur
    Avatar de Bisûnûrs
    Profil pro
    Développeur Web
    Inscrit en
    Janvier 2004
    Messages
    9 868
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2004
    Messages : 9 868
    Points : 16 258
    Points
    16 258
    Par défaut
    Tu n'as pas le droit d'imbriquer des form.

  3. #3
    Membre régulier
    Profil pro
    Technicien Informatique
    Inscrit en
    Février 2006
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Technicien Informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 187
    Points : 89
    Points
    89
    Par défaut validation champs formulaire
    Merci pour la suggestion,
    c'est une erreur de ma part...

    j'ai modifié le code pour rectifier cette erreur et pouvoir utiliser un fichier externe..
    Mais je coince toujours pour le fonctionnement
    Mon code est il correct ?
    L'endroit ou est placé l'instruction <script> </script> est elle adaptée ?

    Merci encore pour votre aide, vos conseils et astuces !

    Jean Marc


    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
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    // javascript test.js
    <script language="jscript">
    function control_classe() 
    { 
    if (document.form_ajout.nom_p.value==""); 
    { 
    alert("Veuillez saisir le nom de la personne"); 
    return false; 
    } 
    else 
    { 
    if (document.form_ajout.prenom_p.value=="") 
    { 
    alert("Veuillez saisir le prénom de la personne"); 
    return false; 
    } 
    else 
    { 
    return true; 
    } 
    } 
    }
    </script> 
     
     
     
     
    //page en cours
    <script language="JavaScript" type="text/javascript" src="test.js"></script>
     <form action="ajouter.php" method="POST" name="form1" OnSubmit="return control_classe()">
        <br>
                <table  border="0" cellpadding="0" cellspacing="0" class="conteneur">
                  <tr valign="top">
                    <td width="50%"><table border="0" cellpadding="1" cellspacing="0" class="detailMaj" >
                        <tr>
                          <td colspan="2" class="titre">Identit&eacute;</td>
                        </tr>
                        <tr>
                          <td colspan="2" align="center" ><input type="radio" name="radiobutton" value="monsieur">
                            Mr&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="radiobutton" value="madame">
                            Mme&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="radiobutton" value="mademoiselle">
                            Mlle                        
                            <input name="id_civ" type="hidden" value="1"></td>
                        </tr>
                        <tr>
                          <th width="22%"><label for="nom">Nom</label></th>
                          <td width="78%"><input name="nom_p" type="text" class="input" size="30" maxlength="32" id="nom">
                              <span class="obligatoire">*</span></td>
                        </tr>
          <tr>
                          <th><label for="nomnaissance">Pr&eacute;nom(s)</label></th>
                          <td><input name="prenom_p" type="text" class="input" size="30" maxlength="32" id="prenom">
                           <span class="obligatoire">*</span> </td>
                        </tr>
                        <tr>
                          <th><label for="commune">Qualit&eacute;</label></th>
                          <td></label><span class="obligatoire">
                          <label>
           <? 
          echo("<select name='qualite' size='1' id='qual_id'>");
          while($data=mysql_fetch_array($resultat_qual)){
           $type=$data['type'];
           echo"<option value=\"$type\">$type.</option>";
           };
           ?>                     
                          </select>
                          </label>
                            </span></td>
                        </tr>
                        <tr>
                          <th colspan="2"><label for="qualite"><br>
                          </label></th>
                        </tr>
                        <tr>
                          <td colspan="2" class="titre">Adresse</td>
                        </tr>
                        <tr>
                          <td colspan="2" align="center" >&nbsp;</td>
                        </tr>
                        <tr>
                          <th><label for="rue">Rue</label></th>
                          <td><textarea name="nom_rue" cols="30" rows="3" class="input" id="nom"></textarea>
                              <span class="obligatoire">*</span></td>
                        </tr>
                        <tr>
                          <th><label for="code_postal">Code Postal</label></th>
                          <td><input name="cp_com" type="text" class="input" size="5" maxlength="5" id="CP">
                          <input name="com_id" type="hidden" value="12"></td>
                        </tr>
                        <tr>
                          <th><label for="ville">Ville</label></th>
                          <td><input name="nom_com" type="text" class="input" size="30" maxlength="32" id="ville"></td>
                        </tr>
                        <tr>
                          <th><label for="tel_p">T&eacute;l&eacute;phone</label></th>
                          <td><input type="text" name="tel_ref1" size="10" class="input" id="tel_p">
                            (Domicile) <span class="obligatoire">*</span></td>
                        </tr>
                        <tr>
                          <th colspan="2">&nbsp;</th>
                        </tr>
                        <tr>
                          <td colspan="2" class="titre">Association</td>
                        </tr>
                        <tr>
                          <th colspan="2">&nbsp;</th>
                        </tr>
                        <tr>
                          <th><label for="asso"></label></th>
                          <td>
                            <label></label><span class="obligatoire"><label>
                            <? 
          echo("<select name='asso_id' size='1' id='asso_id'>");
          while($data=mysql_fetch_array($resultat)){
           $type=$data['nom_a'];
           echo"<option value=\"$type\">$type.</option>";
           };
           
                             ?>
                              </select>
                          </label>
                          </span></td>
                        </tr>
                        <tr>
                          <th colspan="2">&nbsp;</th>
                        </tr>
                    </table></td>
                    <td width="50%"><table border="0" cellpadding="1" cellspacing="0" class="detailMaj" summary="Bloc Referents;">
                      <tr>
                        <td colspan="2" class="titre">R&eacute;f&eacute;rent(s) </td>
                      </tr>
                      <tr>
                        <th colspan="2">&nbsp;</th>
                      </tr>
                      <tr>
                        <th colspan="2"><div align="center">principal</div></th>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" ><input type="radio" name="radiobutton" value="radiobutton">
                          Mr&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mme&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mlle</td>
                      </tr>
                      <tr>
                        <th><label for="label5">Nom</label></th>
                        <td><input name="nom_ref1" type="text" class="input" size="30" maxlength="32" id="label5">
                            <span class="obligatoire">*</span></td>
                      </tr>
                      <tr>
                        <th><label for="label6">Pr&eacute;nom(s)</label></th>
                        <td><input name="Prenom_ref1" type="text" class="input" size="30" maxlength="32" id="label6">
                            <span class="obligatoire">*</span> </td>
                      </tr>
                      <tr>
                        <th><label for="label6">Fonction</label></th>
                        <td><label>
                            <? 
          echo("<select name='ref_id' size='1' id='ref_id'>");
          while($data=mysql_fetch_array($resultat_ref)){
           $type=$data['fonction'];
           echo"<option value=\"$type\">$type.</option>";
           };
           
                             ?>
         
         
         
         
         
                       
                            </select>
                            <span class="obligatoire">*</span></label></td>
                      </tr>
                      <tr>
                        <th><label for="label4">T&eacute;l&eacute;phone</label></th>
                        <td><input type="text" name="tel_ref1" size="10" class="input" id="label4">
                          (Domicile) 
                          <span class="obligatoire">*</span></td>
                      </tr>
                      <tr>
                        <th colspan="2">&nbsp;</th>
                      </tr>
                      <tr>
                        <th colspan="2"><div align="center">secondaire</div></th>
                      </tr>
                      <tr>
                        <td colspan="2" align="center" ><input type="radio" name="radiobutton" value="radiobutton">
                          Mr&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mme&nbsp;&nbsp;&nbsp;&nbsp;
                          <input type="radio" name="radiobutton" value="radiobutton">
                          Mlle</td>
                      </tr>
                      <tr>
                        <th><label for="label7">Nom</label></th>
                        <td><input name="nomR2" type="text" class="input" size="30" maxlength="32" id="label7"></td>
                      </tr>
                      <tr>
                        <th><label for="label8">Pr&eacute;nom(s)</label></th>
                        <td><input name="prenomR2" type="text" class="input" size="30" maxlength="32" id="label8"></td>
                      </tr>
                      <tr>
                        <th><label for="label8">Fonction</label></th>
                        <td><input name="fonctionR2" type="text" class="input" size="30" maxlength="32" id="label8"></td>
                      </tr>
                      <tr>
                        <th><label for="label9">T&eacute;l&eacute;phone</label></th>
                        <td><input type="text" name="telR2" size="10" class="input" id="label9">
                          (Domicile) </td>
                      </tr>
                      <tr>
                        <th height="20" colspan="2">&nbsp;</th>
                      </tr>
                    </table></td>
                  </tr>
                </table>
                <table width="757" border="0" cellpadding="0" cellspacing="0" class="validation" summary="Zone de bouton : Suivant">
                  <tr>
                    <td height="24"><input name="enregistrer" type="submit" class="bouton" id="Submit" title="Bouton : enregistrer" value="enregistrer">
                    </td>
                  </tr>
                </table>                                                        
    </form>
    Jean Marc

Discussions similaires

  1. Validation champs formulaire
    Par totot dans le forum jQuery
    Réponses: 1
    Dernier message: 27/02/2014, 22h34
  2. Valider champs formulaire -> NetBeans Builder
    Par SuperArbre dans le forum Débuter
    Réponses: 2
    Dernier message: 20/10/2012, 12h53
  3. Réponses: 16
    Dernier message: 12/05/2010, 22h28
  4. Colorer champs formulaire non validés..
    Par socket77 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 11/03/2008, 10h27
  5. Réponses: 3
    Dernier message: 27/08/2007, 23h35

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