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 :

utilisation de la fonction alert


Sujet :

JavaScript

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 240
    Par défaut utilisation de la fonction alert
    bonjour voila mon script! jaimerai rajouter un test ki di ke si je ne rempli pa le champs "jenvoi" ba jai une alerte qui me demande de la remplir lorsque je clike sur le bouton envoyer.
    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
     
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Nouvelle page 1</title>
    </head>
    <body>
    <script>
    function change_action(name)
    {
    if (name == "gen") 
    { 
    if(nombre1 == '')
    {
    alert("remplir les champs");
    <?
    return(0);
    ?>
    }
    document.form.method="post"; 
    document.form.action = "envoi4.php"; 
    document.form.target="_blank";
    }
    else 
    {
    document.form.action = "newsletter2.php"; 
    document.form.method="post";
    }
    document.form.submit();
    }
    </script> 
    <form name="form">
    <table cellpadding="10">
    <tr>
    <td width=261>j'envoi de</td>
    <td><input name=nombre1 type=text ></input></td>
    </tr>
    <tr>
    <td width=261>à</td>
    <td><input name=nombre2 type=text ></input></td>
    </tr>
     
    <tr>
    <td width=261>Nom de l'auteur:</td>
    <td><input name=noma type=text></input></td>
    </tr>
     
    <tr>
    <td width=261>Addresse de l'auteur:</td>
    <td><input name=adda type=text value="alfa@beta.com input></td>
    </tr>
    <tr>
    <td width=261>Sujet du message:</td>
    <td><input name=sujet type=text value="alfa"></input></td>
    </tr>
    <tr><th colspan=3>
    <textarea name=entete rows="9" cols="72"></textarea>
    </th></tr>
    <tr>
    <th><input type=text name=titre1></input></th>
    <th><input type=text name=titre2></input></th>
    <th><input type=text name=titre3></input></th>
    </tr><tr>
    <th><textarea name=corps1 rows="9" cols="30"></textarea></th>
    <th><textarea name=corps2 rows="9" cols="30"></textarea></th>
    <th><textarea name=corps3 rows="9" cols="30"></textarea></th>
    </tr><tr>
    <th><input type=text name=pied1></input></th>
    <th><input type=text name=pied2></input></th>
    <th><input type=text name=pied3></input></th>
    </tr>
    <tr>
    <th colspan=3><input type=text name=titrebas size="72"></input></th>
    </tr>
    <tr>
    <th colspan=3>
    <textarea name=pied rows="9" cols="72"></textarea><br/>
    </th>
    </tr>
    </tr>
    <tr><th align=right> lien 1:</th><th colspan=2>
    <input type=text name=lien1 size="50"></input>
    </th></tr>
    <tr><th align=right height="47"> lien 2:</th><th colspan=2 height="47">
    <input type=text name=lien2 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 3:</th><th colspan=2>
    <input type=text name=lien3 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 4:</th><th colspan=2>
    <input type=text name=lien4 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 5:</th><th colspan=2>
    <input type=text name=lien5 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 6:</th><th colspan=2>
    <input type=text name=lien6 size="50"></input>
    </th></tr>
    </tbody>
    </table>
     
    <input type=submit value="envoyer" name=gen onclick="change_action(this.name)"><br>
    <input type=submit value="generer" name=gen2 onclick="change_action(this.name)">
    </form>
     
     
    </body>
    </html>

  2. #2
    Expert confirmé Avatar de Mr N.
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 5 418
    Par défaut
    Merci :
    1. d'écrire convenablement
    2. d'utiliser les balises [code] (le petit # sur l'editeur) pour mettre en valeur le code
    3. de poster au bon endroit => forum javascript

  3. #3
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Par défaut
    si tu veux le gérer comme ca, met des input type button au lieu de submit

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 240
    Par défaut
    jai mi des button mai je ne sai toujours pas ou je dois utiliser la fonction alert

  5. #5
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868

  6. #6
    Membre expérimenté Avatar de Tdeny
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    287
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 287
    Par défaut
    Bonjour,

    D'abord, tu as une erreur dans le ligne ci-dessous :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <td>
    <input name=adda type=text value="alfa@beta.com input>
    </td>
    Correction, je suppose :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <td>
    <input name=adda type=text value="<a href="mailto:alfa@beta.com">alfa@beta.com</a>"</input>
    </td>
    Ensuite... tu contrôles tes input obligatoires (mets des * devant) avec les fonctions if / else (alert("non rempli") exemple simplifié.
    Et regarde dans la FAQ comment faire un document.form.submit() en cliquant sur un input type text.

  7. #7
    Membre éclairé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 240
    Par défaut
    oui tdeny ta raison cetai une erreur merci! moi jai fai le test suivant mai l'alerte na passe pa et je ne sais pa pourkoi:
    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
     
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Nouvelle page 1</title>
    </head>
    <body>
    <script language="javascript"> 
    function verification(){
        if(document.getElementById('nombre1').value == ""){
            alert ('Vous avez oublié de saisir un champ!!!!');
            return (0);
        }
    }
     
     
    function gopage(page) 
    {
        document.formulaire.action = page; 
        document.formulaire.submit(); 
    } 
    </script>
     
     
    <form name="formulaire" method="post" action="" onSubmit="return verification()"> 
    <table cellpadding="10">
    <tr>
    <td width=261>nombre1</td>
    <td><input name=nombre1  type=text ></input></td>
    </tr>
    <tr>
    <td width=261><label for="jusque">à</label></td>
    <td><input name=nombre2  type=text ></input></td>
    </tr>
     
    <tr>
    <td width=261>Nom de l'auteur:</td>
    <td><input name=noma type=text></input></td>
    </tr>
     
    <tr>
    <td width=261>Addresse de l'auteur:</td>
    <td><input name=adda type=text value="<A href="mailto:alfa@beta.com"></input></td">alfa@beta.com"></input></td>
    </tr>
    <tr>
    <td width=261>Sujet du message:</td>
    <td><input name=sujet type=text value="alfa"></input></td>
    </tr>
    <tr><th colspan=3>
    <textarea name=entete rows="9" cols="72"></textarea>
    </th></tr>
    <tr>
    <th><input type=text name=titre1></input></th>
    <th><input type=text name=titre2></input></th>
    <th><input type=text name=titre3></input></th>
    </tr><tr>
    <th><textarea name=corps1 rows="9" cols="30"></textarea></th>
    <th><textarea name=corps2 rows="9" cols="30"></textarea></th>
    <th><textarea name=corps3 rows="9" cols="30"></textarea></th>
    </tr><tr>
    <th><input type=text name=pied1></input></th>
    <th><input type=text name=pied2></input></th>
    <th><input type=text name=pied3></input></th>
    </tr>
    <tr>
    <th colspan=3><input type=text name=titrebas size="72"></input></th>
    </tr>
    <tr>
    <th colspan=3>
    <textarea name=pied rows="9" cols="72"></textarea><br/>
    </th>
    </tr>
    </tr>
    <tr><th align=right> lien 1:</th><th colspan=2>
    <input type=text name=lien1 size="50"></input>
    </th></tr>
    <tr><th align=right height="47"> lien 2:</th><th colspan=2 height="47">
    <input type=text name=lien2 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 3:</th><th colspan=2>
    <input type=text name=lien3 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 4:</th><th colspan=2>
    <input type=text name=lien4 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 5:</th><th colspan=2>
    <input type=text name=lien5 size="50"></input>
    </th></tr>
    <tr><th align=right> lien 6:</th><th colspan=2>
    <input type=text name=lien6 size="50"></input>
    </th></tr>
    </tbody>
    </table>
     
    <input type="button" value="envoyer" onClick="gopage('envoi4.php')"><br>
    <input type="button" value="generer" onClick="gopage('newsletter.php')"> 
    </form>
    </body>
    </html>

  8. #8
    Membre expérimenté Avatar de Tdeny
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    287
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 287
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    function verification(){
    if(document.getElementById('nombre1').value == ""){
    alert ('Vous avez oublié de saisir un champ!!!!');
    return (0);
    }
    }
    C'est ton return (0) qui ne va pas. D'abord ça s'écrit return 0, et à priori dans un else(...), vu que c'est ce que ça doit renvoyer si tout le reste est faux.
    Le problème pour toi est que comme tu l'as mis dans le if, c'est ce que ça renvoie en écrasant ton alert. C'est la déduction logique.

Discussions similaires

  1. [LG]Utilisation de la fonction time
    Par kmitz dans le forum Langage
    Réponses: 4
    Dernier message: 08/04/2005, 13h05
  2. Utilisation de la fonction de déploiement
    Par mchicoix dans le forum XMLRAD
    Réponses: 4
    Dernier message: 01/03/2005, 14h35
  3. [LG]Utilisation de la fonction Random
    Par chloe95 dans le forum Langage
    Réponses: 1
    Dernier message: 01/03/2005, 14h20
  4. Utilisation de la fonction qsort
    Par Jsmeline dans le forum C
    Réponses: 8
    Dernier message: 28/01/2005, 12h40
  5. [LG]librairies : utiliser seulement quelques fonctions
    Par wwwroom dans le forum Langage
    Réponses: 13
    Dernier message: 14/05/2004, 22h50

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