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 :

Pb de verification Javascript


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    220
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 220
    Par défaut Pb de verification Javascript
    j ai un pb de la fonction valider qui est censé verifier le champ nom et prenom mais il ne le fait pas il valide mon formulaire sans prendre en compte si le champ est vide ou pas.

    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
    <script language="javascript">
    	function valider(){
    		if (document.formstock.nom.value.length == 0){
    			alert("Veuillez saisir votre nom");
    			document.formstock.nom.focus();
    			return;
    		}
     
    		if (document.formstock.processeur.value.length == 0){
    			alert("Veuillez saisir le processeur");
    			document.formstock.processeur.focus();
    			return;
    		}		
     
    		document.formstock.submit();
    	}
    </script>
    mon formulaire

    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
    </head>
     
    <body bgcolor="#CCCCCC">
    <tr>
    <td bgcolor="#FFFFFF"><a href="#" onclick="javascript:if (window.confirm('Etes vous sur? Pensez à effacer le client précédement ajouté dans la BDD si ok (=> Menu 3) !')){document.location.href='index.php';}"><font color="#25AD3D">Acceuil</a>></font>
    </td>
    </tr>
    <form method="POST" action="formstock1bis.php" enctype="multipart/form-data" name="formstock">
    <div align="center"></div>
    <p align="center">
     
    <?
    //echo "<INPUT TYPE='hidden' NAME='id_produit' VALUE='" . $id . "'/>";
    ?>
     
    <table width="566" border="0" align="center">
    <p align="center">
    </p><tr>
    	<td><font face="Verdana" size="2">Modéle</font></td>
    			<td>
    				<font face="Verdana" size="2">MAC:</font> <input type=radio name="modele" value="Apple">
     
        			<font face="Verdana" size="2">PC:</font> <input name="modele" type=radio value="Pc" checked="checked" /><br/></td>
    	</tr><tr>
    	<td><font face="Verdana" size="2">Type</font></td>
    			<td>
    				<select name="type">
    				<option value="fixe">Fixe</option>
    				<option value="portable">Portable</option>
    				<option value="peripherique">Périphérique</option>
    				<option value="accessoires">Accessoires</option>
    				</select>	</td>
    	</tr><tr>			
          <td><font face="Verdana" size="2">Nom</font></td>
          <td><input name="nom" type="text"style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;"></td>
        </tr><tr>
    	  <td><font face="Verdana" size="2">Processeur</font></td>
          <td><input name="processeur" type="text"style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;"></td>
        </tr><tr>
    	  <td width><font face="Verdana" size="2">Mémoire Video</font></td>
          <td width><input name="memoire_video" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Mémoire Vive</font></td>
          <td width><input name="memoire_vive" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Disque Dur</font></td>
          <td width><input name="disque_dur" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Taille Ecran</font></td>
          <td width><input name="taille_ecran" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Lecteur Optique</font></td>
          <td width><input name="lecteur_optique" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    		</tr><tr> 
    	  <td width><font face="Verdana" size="2">Systéme d'Opération</font></td>
          <td width><input name="os" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Connectique</font></td>
          <td width><input name="connectique" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Accessoires</font></td>
          <td width><input name="accessoires" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Graveur</font></td>
          <td width><input name="graveur" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Prix de la côte d'occasion</font></td>
          <td width><input name="prix_cote_occasion" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Prix d'achat</font></td>
          <td width><input name="prix_achat" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	  <td width><font face="Verdana" size="2">Prix de Vente</font></td>
          <td width><input name="prix_vente" type="text" style="background-color: #FFFFFF;font: Verdana; color: #000000; border: 0px;" ></td>
    	</tr><tr>
    	<td><font face="Verdana" size="2">Sous Garantie</font></td>
    			<td>
    				<font face="Verdana" size="2">Oui:</font> <input type=radio name="sous_garantie" value="Oui">
     
        			<font face="Verdana" size="2">Non:</font> <input name="sous_garantie" type=radio value="Non" checked="checked" /></td>
    	</tr><tr>
     
    		<td width><font face="Verdana" size="2"></font></td>	
    	  <td><textarea  name="textgarantie" cols="50" rows="10" style="background-color: #FFFFFF;font: verdana; color: #000000; border: 0px;" wrap="hard"></textarea></td>
     
    	</tr><tr>
     
    	<td><font face="Verdana" size="2">Vente</font></td>
    			<td>
    				<select name="etat" size="1">
    				<option value="1">Dépôt vente</option>
    				<option value="2" selected="selected">Vente directe</option>
    			        </select>	</td>
    	</tr>
    	<tr>
    	<td><font face="Verdana" size="2">Etat</font></td>
    			<td>
    				<select name="etat" size="1">
    				<option value="1" selected="selected">Non vendu</option>
    				<option value="2">Vendu</option>
    			        </select>	</td>
    	</tr>
    	<tr>
    		<td>Photo</td>
    		<td><input type="file" size="50" name="photo" /></td>
    	</tr>
    	<tr>
          <td valign="top"><input name="pdt_id_clt" type="hidden" id="pdt_id_clt" value="<? echo $_GET["pdt_id_clt"]; ?>" />
          </td>
          <td><div align="center">
    <input type="reset" name="Reset" value="Effacer" >          
    <input type="button" name="envoi" value="Envoyer" onClick="valider()">
            </div></td>
        </tr>
      </table>
      <div align="center"></div>
    </form>
    </body>
    </html>
    je n ai aucun message d erreur!

    Merci

  2. #2
    Membre éclairé Avatar de linar009
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    497
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Juillet 2006
    Messages : 497
    Par défaut
    Essaie peut-être de mettre document.getElementById('processeur')

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    220
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 220
    Par défaut
    Je le mets ou ?

  4. #4
    Membre Expert
    Avatar de FremyCompany
    Profil pro
    Étudiant
    Inscrit en
    Février 2006
    Messages
    2 532
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2006
    Messages : 2 532
    Par défaut
    Exemple :
    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
    <html>
    <body>
    <script language="javascript">
    function valider(){
       var n; var p;
       n=document.getElementsByName("nom")[0]
       p=document.getElementsByName("processeur")[0]
       var res = (
          n.value=="" ? (
             alert("Veuillez entrez le nom !") |
             n.focus() && false
          ) : true &&
          p.value=="" ? (
             alert("Veuillez entrez le processeur!") |
             p.focus() && false
          ) : true
       )
       if (res==0) {res=false}
       return res;
    }
    </script>
    <form onsubmit="return (valider())" action="javascript:alert('submited')">
    <input name="nom" />
    <input name="processeur" />
    <input type="submit" />
    </form>
    </body>
    </html>

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    220
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 220
    Par défaut
    non j ai pas compri

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 10/07/2011, 19h20
  2. submit et verification javascript
    Par murder dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 20/01/2010, 17h41
  3. autre probleme javascript de verif des champs
    Par Damish dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 16/10/2006, 15h45
  4. Boucle JavaScript pour verif de formulaire
    Par VooDooNet dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 19/09/2006, 17h34
  5. Verification syntaxe fonction javascript
    Par calitom dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 12/09/2006, 16h02

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