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 :

contrôle de saisie


Sujet :

JavaScript

  1. #1
    Membre confirmé Avatar de oceane751
    Profil pro
    Intégrateur Web
    Inscrit en
    Novembre 2004
    Messages
    1 280
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1 280
    Points : 575
    Points
    575
    Par défaut contrôle de saisie
    bonjour!
    voilà je rencontre un problème avec mon bout de code javascript
    en effet, lorsque je veux contrôler la civilité d'une personne remplissant le formulaire, qu'elle est renseigné ou pas, j'obtient l'erreur qui suit :
    en 3 fois "vous devez renseigner une civilité"

    voici mon code :
    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
     
    <html>
    <head>
    <SCRIPT language="javascript">
     
    function testvalidation()
    {
     var ok = false;
     for (i in document.formSI.elements["civilite"])
       {
           if (document.formSI.elements["civilite"][i].checked)
           {
               ok = true;
               break;
     
     
                }
     
               if (!ok)
               alert("Vous devez renseigner une civilité");
     
    if(document.formSI.nom.value == "")
    {
    alert ('veuillez entrer votre Nom');
    document.formSI.nom.focus();
    return false; 
    }
     
    if(document.formSI.prenom.value == "")
    { 
    alert ('veuillez entrer un prenom');
    document.formSI.prenom.focus();
    return false; 
    } 
     
    else {return true;}
    }
     
     
     
     
     
     
     
    </SCRIPT>
     
    <title>Stagiaire Inscription</title>
     
    </head>
     
    <body>
    <font face ="verdana">
     
    <table border="0" width="100%" height="10" background="stage_fond.jpg">
    <form name="formSI" action="StagiaireInscriptionIdentification.php" method="post"  onSubmit=" return testvalidation()" enctype="multipart/form-data" >
      <tr>
        <td width="98%" height="41" colspan="2">
          &nbsp;</td>
        <td width="1%" height="41">&nbsp;</td>
      </tr>
      <tr>
        <td width="90%" height="41" colspan="2">
          <p align="center"><b><font size="6">Identification</font></b></td>
        <td width="5%" height="41">&nbsp;</td>
      </tr>
      <tr>
        <td width="90%" height="41" colspan="2">
          <p align="center"><font size="2">Vous postuler pour un domaine de stage. Le sujet de stage sera défini avec le responsable de stage si votre candidature est retenue pour un entretien</font></td>
        <td width="5%" height="41"></td>
      </tr>
      <tr>
        <td width="91%" height="124" colspan="2">
          <table border="0" width="100%" cellspacing="0">
            <tr>
              <td width="102%" align="right" colspan="4">
                <p align="left">
     
                               			<tr> 
                               				<td align="center" nowrap="nowrap" width="194">
                                              <p align="right"><b><font size="2">Civilité</font></b></p>
                                            </td>
                               				<td width="118">
                                              <p align="right"><font size="2">M<sup>elle</sup> <input type="radio" name="civilite" value="Melle"</td>
                                              </font>
                               				<td width="118">
                                              <p align="center"><font size="2">M<sup>me</sup> <input type="radio" name="civilite" value="Mme"</td>
                                              </font>
                               				<td width="117"><font size="2">M <input type="radio" name="civilite" value="M"</td>
                                              </font>
                               			</tr>
     
            <tr>
              <td width="29%" align="right"><b><font size="2">Nom</font></b></td>
              <td width="73%" colspan="3"><font size="2"><input type="text" name="nom" size="30"></font></td>
            </tr>
            <tr>
              <td width="29%" align="right"><b><font size="2">Prénom</font></b></td>
              <td width="73%" colspan="3"><font size="2"><input type="text" name="prenom" size="30"></font></td>
            </tr>
            <tr>
              <td width="29%" align="right"><b><font size="2">Date de naissance</font></b></td>
              <td width="15%"><font size="2"><select name="jnais">
                               				<option value="" selected>--jour--</option>
     
    										<option value=1>1 </option><option value=2>2 </option><option value=3>3 </option><option value=4>4 </option><option value=5>5 </option><option value=6>6 </option><option value=7>7 </option><option value=8>8 </option><option value=9>9 </option><option value=10>10 </option><option value=11>11 </option><option value=12>12 </option><option value=13>13 </option><option value=14>14 </option><option value=15>15 </option><option value=16>16 </option><option value=17>17 </option><option value=18>18 </option><option value=19>19 </option><option value=20>20 </option><option value=21>21 </option><option value=22>22 </option><option value=23>23 </option><option value=24>24 </option><option value=25>25 </option><option value=26>26 </option><option value=27>27 </option><option value=28>28 </option><option value=29>29 </option><option value=30>30 </option><option value=31>31 </option>              							</select></font></td>
              <td width="18%"><font size="2"><select name="mnais">
                               				            <option value="" selected>---mois---</option>
                  										<option value="01">Janvier</option>
                  										<option value="02">Février</option>
                  										<option value="03">Mars</option>
                  										<option value="04">Avril</option>
                  										<option value="05">Mai</option>
                  										<option value="06">Juin</option>
                  										<option value="07">Juillet</option>
                  										<option value="08">Août</option>
                  										<option value="09">Septembre</option>
                  										<option value="10">Octobre</option>
                  										<option value="11">Novembre</option>
                  										<option value="12">Décembre</option>
                  										</select></font></td>
              <td width="38%"><font size="2"><select name="annais"  onChange="CheckData()">
    										<option value="" selected>---Année---</option>
     
    										<option value=1952>1952 </option><option value=1953>1953 </option><option value=1954>1954 </option><option value=1955>1955 </option><option value=1956>1956 </option><option value=1957>1957 </option><option value=1958>1958 </option><option value=1959>1959 </option><option value=1960>1960 </option><option value=1961>1961 </option><option value=1962>1962 </option><option value=1963>1963 </option><option value=1964>1964 </option><option value=1965>1965 </option><option value=1966>1966 </option><option value=1967>1967 </option><option value=1968>1968 </option><option value=1969>1969 </option><option value=1970>1970 </option><option value=1971>1971 </option><option value=1972>1972 </option><option value=1973>1973 </option><option value=1974>1974 </option><option value=1975>1975 </option><option value=1976>1976 </option><option value=1977>1977 </option><option value=1978>1978 </option><option value=1979>1979 </option><option value=1980>1980 </option><option value=1981>1981 </option><option value=1982>1982 </option><option value=1983>1983 </option><option value=1984>1984 </option><option value=1985>1985 </option><option value=1986>1986 </option><option value=1987>1987 </option><option value=1988>1988 </option>                           				</selected></font></td>
            </tr>
          </table>
        </td>
        <td width="10%" height="124"></td>
      </tr>
      <tr>
        <td width="91%" height="44" colspan="2">
          <p align="right"><img border="0" src="images/trait.jpg" width="530" height="7"></p>
        </td>
        <td width="10%" height="44">&nbsp;</td>
      </tr>
      <tr>
        <td width="46%" height="44">
          <p align="right"><input type="reset" value="effacer"></td>
        <td width="45%" height="44"><input type="submit" value="valider"></td>
        <td width="10%" height="44">&nbsp;</td>
      </tr>
      <tr>
        <td width="91%" height="44" colspan="2"></td>
        <td width="10%" height="44"></td>
      </tr>
      </font>
      </form>
    </table>
     
    </body>
     
    </html>
    ps : je reprends ce code, on m'a juste demandé de faire un contrôle de saisie. le code est un peu crade, je l'arrangerais plus tard...

  2. #2
    Expert éminent

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Points : 7 641
    Points
    7 641
    Par défaut Re: contrôle de saisie
    Citation Envoyé par oceane751
    for (i in document.formSI.elements["civilite"])
    {
    if (document.formSI.elements["civilite"][i].checked)
    {
    ok = true;
    break;


    }
    }
    if (!ok)
    alert("Vous devez renseigner une civilité");

    .....

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 93
    Points : 114
    Points
    114
    Par défaut
    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
    function testvalidation() { 
    	var ok = false; 
    	for (var i = 0 ; i < document.formSI.civilite.length ; i++) { 
    		if (document.formSI.civilite[i].checked) { 
    			ok = true; 
    			break; 
    		} 
    	}
    	if (!ok) alert("Vous devez renseigner une civilité"); 
     
    	if(document.formSI.nom.value == "") { 
    		alert ('veuillez entrer votre Nom'); 
    		document.formSI.nom.focus(); 
    		return false; 
    	} 
     
    	if(document.formSI.prenom.value == "") { 
    		alert ('veuillez entrer un prenom'); 
    		document.formSI.prenom.focus(); 
    		return false; 
    	} else {
    		return true;
    	} 
     
    }

  4. #4
    Membre confirmé Avatar de oceane751
    Profil pro
    Intégrateur Web
    Inscrit en
    Novembre 2004
    Messages
    1 280
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1 280
    Points : 575
    Points
    575
    Par défaut
    meci beaucoup, c'était une { d'oubliée

    alors voici le code :
    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
     
    function testvalidation()
    {
     var ok = false; 
     for (i in document.formSI.elements["civilite"])
       { 
           if (document.formSI.elements["civilite"][i].checked)
           { 
               ok = true;
               break; 
           }
     
                } 
     
               if (!ok) 
               alert("Vous devez renseigner une civilité"); 
     
    if(document.formSI.nom.value == "") 
    { 
    alert ('veuillez entrer votre Nom'); 
    document.formSI.nom.focus(); 
    return false;
    } 
     
    if(document.formSI.prenom.value == "") 
    { 
    alert ('veuillez entrer un prenom'); 
    document.formSI.prenom.focus(); 
    return false; 
    } 
     
    else {return true;} 
    }
    mais ej voudrais savoir s'il était possible de faire qu'une seule et unique
    fenetre pour tous les elements oubliés (que l'utilisateur n'a pas rempli dans le formulaire)?

  5. #5
    Expert éminent

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Points : 7 641
    Points
    7 641
    Par défaut
    Au lieu de faire un alert à chaque fois, rajoute un message dans une chaine de caractères:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    message+="Vous avez oublié votre adresse mail! \n";
    Il ne reste plus qu'à afficher ce message en alert à la fin des test, si il n'est pas vide (attention à l'initialisation de la chaine, et à la gestion des retours à la ligne).

    Bonne chance

Discussions similaires

  1. Contrôle de saisie de valeurs doublons de la clé primaire.
    Par abdelghani_k dans le forum Bases de données
    Réponses: 5
    Dernier message: 26/02/2006, 22h12
  2. Contrôle de saisie formulaire
    Par miram dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 02/02/2006, 08h33
  3. contrôle de saisie sur un espace
    Par oceane751 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 12/01/2006, 12h04
  4. contrôle de saisie menu déroulant
    Par shnouf dans le forum Général JavaScript
    Réponses: 11
    Dernier message: 05/01/2006, 16h30
  5. [debutant] contrôle de saisie et formulaire
    Par oceane751 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 27/11/2005, 22h29

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