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 :

Formulaire select : afficher/Masquer un autre formulaire en fonction du choix


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Par défaut Formulaire select : afficher/Masquer un autre formulaire en fonction du choix
    Bonjour à tous,
    Etant débutant en javascript et codant un peu en php, jaurais souhaité afficher un formulaire en fonction du choix du visiteur dans un formulaire de type select...
    J'ai cherché la réponse à ma question sur le net et je suis tombé sur un script qui collait assez bien au mien.
    En fait je voudrais, quand le visiteur selectionne "entreprise" afficher le "form_entreprise" à coté.
    En adaptant le script que j'ai trouvé au mien cela me donne ceci :
    .....mais hélas le formulaire reste toujours caché, meme lorsque je sélectionne l'option "entreprise"...

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
     
    <script language="JavaScript">
     
    function affiche_entreprise() {
    if (document.votre_activite.activite.options.value == "entreprise")
    document.getElementById('form_entreprise').style.visibility = 'visible';
    else
    document.getElementById('form_entreprise').style.visibility = 'hidden';
    }
    </script>
     
    </head>
     
    <body>
     
    <form name="votre_activite" action="" method="post">
     
    <label><strong>Votre activité :</strong></label> <select name="activite" OnChange="affiche_entreprise();">
     
      <option name= value="particulier">Particulier</option>
      <option value="association">Association</option>
      <option value="entreprise">Entreprise</option>
                                                     </select>
        <br/>
    </form>   
     
    <span id="form_entreprise" style="visibility:hidden">
     
         <form method="post" action="">
     
          <label><strong>Nom :</strong></label> <input type="text" name="nom_entreprise"/><br/>
     
          <label><strong>Adresse :</strong></label> <input type="text" name="adresse_entreprise"/><br/>
     
         <label><strong>Code Postal :</strong></label> <input type="text" name="code_entreprise"/><br/>
     
         <label><strong>Ville :</strong></label> <input type="text" name="ville_entreprise"/><br/>
     
         <label><strong>Secteur d'activité :</strong></label> <input type="text" name="activite_entreprise"/><br/>
     
         <label><strong>Type de société :</strong></label> <select name="type_entreprise">
     
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
         </select>
     
    </form></span>
     
    </select>
    </form>
    </body>
    </html>

    Voila, si quelqu'un a la solution à mon problème je suis preneur d'un petit coup de main.
    Merci d'avance pour votre aide...

  2. #2
    Membre Expert
    Avatar de Jumano
    Profil pro
    Inscrit en
    Février 2007
    Messages
    1 163
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 1 163
    Par défaut
    Bonjour,
    Ton script fonctionne parfaitement chez moi, testé en local avec WAMP

  3. #3
    Membre chevronné Avatar de htr999
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 331
    Par défaut
    question de compatibilité
    il marche sous >= IE6 mais pas sous FFX
    j'ai WAMP 5

    a+

  4. #4
    Membre Expert
    Avatar de Jumano
    Profil pro
    Inscrit en
    Février 2007
    Messages
    1 163
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 1 163
    Par défaut
    Autant pour moi je n'avais testé que sous IE

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Par défaut
    Ah ok je l'ai testé en local wamp mais sous Firefox....
    Quelqu'un saurait comment y remédier ou ce n'est pas possible...?

  6. #6
    Membre chevronné Avatar de htr999
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 331
    Par défaut

    c'est au niveau du test
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if (document.votre_activite.activite.options.value == "entreprise")
    FFX ne comprend pas
    document.votre_activite.activite.options.value
    a+

  7. #7
    Membre chevronné Avatar de htr999
    Profil pro
    Étudiant
    Inscrit en
    Février 2008
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2008
    Messages : 331
    Par défaut
    modif du test
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    if (document.votre_activite.activite.selectedIndex == 2)
    ...
    le voici
    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
     
    <script language="JavaScript">
     
    function affiche_entreprise() {
    if (document.votre_activite.activite.selectedIndex == 2)
    document.getElementById('form_entreprise').style.visibility = 'visible';
    else
    document.getElementById('form_entreprise').style.visibility = 'hidden';
    }
    </script>
     
    </head>
     
    <body>
     
    <form name="votre_activite" action="" method="post">
     
    <label><strong>Votre activité :</strong></label> <select name="activite" OnChange="affiche_entreprise();">
     
      <option value="particulier">Particulier</option>
      <option value="association">Association</option>
      <option value="entreprise">Entreprise</option>
                                                     </select>
        <br/>
    </form>   
     
    <span id="form_entreprise" style="visibility:hidden">
     
         <form method="post" action="">
     
          <label><strong>Nom :</strong></label> <input type="text" name="nom_entreprise"/><br/>
     
          <label><strong>Adresse :</strong></label> <input type="text" name="adresse_entreprise"/><br/>
     
         <label><strong>Code Postal :</strong></label> <input type="text" name="code_entreprise"/><br/>
     
         <label><strong>Ville :</strong></label> <input type="text" name="ville_entreprise"/><br/>
     
         <label><strong>Secteur d'activité :</strong></label> <input type="text" name="activite_entreprise"/><br/>
     
         <label><strong>Type de société :</strong></label> <select name="type_entreprise">
     
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
         </select>
     
    </form></span>
     
    </select>
    </form>
    </body>
    </html>
    a+

Discussions similaires

  1. Réponses: 1
    Dernier message: 25/05/2011, 09h12
  2. Réponses: 2
    Dernier message: 23/10/2008, 17h36
  3. Réponses: 4
    Dernier message: 11/06/2008, 13h38
  4. Réponses: 2
    Dernier message: 03/01/2008, 20h21
  5. Réponses: 13
    Dernier message: 16/04/2007, 18h25

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