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

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    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 expérimenté
    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
    Points : 1 595
    Points
    1 595
    Par défaut
    Bonjour,
    Ton script fonctionne parfaitement chez moi, testé en local avec WAMP

  3. #3
    Membre averti 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
    Points : 394
    Points
    394
    Par défaut
    question de compatibilité
    il marche sous >= IE6 mais pas sous FFX
    j'ai WAMP 5

    a+

  4. #4
    Membre expérimenté
    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
    Points : 1 595
    Points
    1 595
    Par défaut
    Autant pour moi je n'avais testé que sous IE

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    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 averti 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
    Points : 394
    Points
    394
    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 averti 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
    Points : 394
    Points
    394
    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+

  8. #8
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    Par défaut
    Merci beaucoup ca marche parfaitement sous les 2 navigateurs maintenant...

  9. #9
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    Par défaut
    Après réflexion, j'ai quelques questions sur le code que m'a donné htr999 :
    Je tiens à préciser qu'il marche parfaitement mais je voudrais comprendre le principe pour pouvoir faire la meme chose avec l'option "association"...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if (document.votre_activite.activite.selectedIndex == 2)
    Pourquoi tu mets 2 dans la valeur "selectedIndex" ? L'option "entreprise" dans la liste est en effet en 3è position...Quelle valeur faudrait -il que je mette pour l'option "association"

    Comment faire pour ajouter une autre fonction dans le Onchange, est-ce possible...?

    Voila, merci pour votre aide...

    PS: Cette fois ci je vous promet que ce sera la derniere...

  10. #10
    Membre averti 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
    Points : 394
    Points
    394
    Par défaut
    salut
    cela dépend des options que tu as mise dans ton select
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <select name="activite" OnChange="affiche_entreprise();">
     
      <option value="particulier">Particulier</option>
      <option value="association">Association</option>
      <option value="entreprise">Entreprise</option>
                                                     </select>
    il y en a trois Particulier/Association/Entreprise

    dans le test:
    + document correspond à ton document
    + document.votre_activite t'envoie le formulaire nommé votre_activite avec attribut "name"
    + document.votre_activite.activite donne l'élément SELECT de ton formulaire, nommé ACTIVITE
    + document.votre_activite.activite.selectedIndex t'envoie l'élément sélectionné dans ta liste des options (SELECT)

    vu que tu as 3 éléments dans ton SELECT, "PARTICULIER" prend l'index 0 (une convention pour les langages C/Java/... pour le 1er élément d'un tableau, une liste ...), "ASSOCIATION" prend 1 et "ENTREPRISE" prend 2

    donc pour compléter tes tests, il suffit d'ajouter 2 IF-ELSE pour l'index 1 et 2

    j'espère avoir été clair.

    bon courage

    PS. pour l'onChage, je vois pas ce que tu veux faire ?.?

  11. #11
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    Par défaut
    Merci htr999 pour ton aide...
    J'ai recréé une fonction "affiche_association" pour un nouveau test pour afficher son formulaire mais ça ne marche pas :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    function affiche_association() {
    if (document.votre_activite.activite.selectedIndex == 1)
    document.getElementById('form_association').style.visibility = 'visible';
    else
    document.getElementById('form_association').style.visibility = 'hidden';
    }
    Je pense que le pb vient du Onchange, lorsque je fais appel à ma fonction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <select name="activite" OnChange="affiche_entreprise();" "affiche_association();">
    J'ai essayé d'ajouté ma fonction à la suite mais je ne sais pas si c'est possible...

  12. #12
    Membre averti 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
    Points : 394
    Points
    394
    Par défaut
    les modif consistent en l'utilisation d'une seule fonction qui gère l'affichage des formulaires.
    ainsi sur l'événement OnChage, on l'utilise pour affecter les changements.

    par contre le code est assez mal conçu, car si on veut que FormEntreprise s'affiche, il va laisser un blanc énorme avant, à cause des SPAN Caché.

    --> recours possible à la construction dynamique de la page (avec innerHTML par exemple !.!)

    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
    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
    <!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_formulaire() {
    // Particulier
    if (document.votre_activite.activite.selectedIndex == 0)
    document.getElementById('form_particulier').style.visibility = 'visible';
    else
    document.getElementById('form_particulier').style.visibility = 'hidden';
     
    // Association
    if (document.votre_activite.activite.selectedIndex == 1)
    document.getElementById('form_association').style.visibility = 'visible';
    else
    document.getElementById('form_association').style.visibility = 'hidden';
     
    // 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_formulaire();">
     
      <option value="particulier">Particulier</option>
      <option value="association">Association</option>
      <option value="entreprise">Entreprise</option>
                                                     </select>
        <br/>
    </form>   
     
     
      <!-- Particulier -->
    <span id="form_particulier" style="visibility:hidden">
     
         <form method="post" action="">
     
          <label><strong>Nom particulier:</strong></label> <input type="text" name="nom_particulier"/><br/>
     
          <label><strong>Adresse particulier:</strong></label> <input type="text" name="adresse_particulier"/><br/>
     
         <label><strong>Code Postal particulier:</strong></label> <input type="text" name="code_particulier"/><br/>
     
         <label><strong>Ville particulier:</strong></label> <input type="text" name="ville_particulier"/><br/>
     
         <label><strong>Secteur d'activité particulier:</strong></label> <input type="text" name="activite_particulier"/><br/>
     
         <label><strong>Type de société particulier:</strong></label> <select name="type_particulier">
     
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
         </select>
     
    </form></span>
     
     
     
      <!-- Association -->
    <span id="form_association" style="visibility:hidden">
     
         <form method="post" action="">
     
          <label><strong>Nom assoc:</strong></label> <input type="text" name="nom_association"/><br/>
     
          <label><strong>Adresse assoc:</strong></label> <input type="text" name="adresse_association"/><br/>
     
         <label><strong>Code Postal assoc:</strong></label> <input type="text" name="code_association"/><br/>
     
         <label><strong>Ville assoc:</strong></label> <input type="text" name="ville_association"/><br/>
     
         <label><strong>Secteur d'activité assoc:</strong></label> <input type="text" name="activite_association"/><br/>
     
         <label><strong>Type de société assoc:</strong></label> <select name="type_association">
     
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
         </select>
     
    </form></span>
     
     
     <!-- Entreprise -->
    <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>

  13. #13
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    Par défaut
    Ah bah ouais je n'y avais pas pensé...
    Merci beaucoup de ton aide précieuse^^

  14. #14
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    381
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Maroc

    Informations forums :
    Inscription : Novembre 2007
    Messages : 381
    Points : 180
    Points
    180
    Par défaut
    Salut,
    Au premier chargement de la page l'élément afficher dans la liste sera "Particulier" mais son formulaire ne va pas s'afficher, pour l'afficher mets ça dans la balise body <body onload="affiche_formulaire()"> sinon tu laisses le premier élément de la liste vide ou bien tu mets un titre du genre "selectionner une activité" mais dans ce cas la du dois faire des modifications sur ta fonction.
    A+

  15. #15
    Membre expérimenté
    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
    Points : 1 595
    Points
    1 595
    Par défaut
    Bonjour,
    Si le fait de rafraichir ta page ne pause pas de problème tu peux utiliser une alternative en PHP :
    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
     
    <!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>
    </head>
     
    <body>
    <form name="votre_activite" action="" method="get">
    <label><strong>Votre activité :</strong></label>
    <select name="activite" OnChange="form.submit();">
      <option value="" <?php if (!(strcmp("", $_GET['activite']))) {echo "selected=\"selected\"";} ?>>Sélectionnez une activité</option>
      <option value="particulier" <?php if (!(strcmp("particulier", $_GET['activite']))) {echo "selected=\"selected\"";} ?>>Particulier</option>
      <option value="association" <?php if (!(strcmp("association", $_GET['activite']))) {echo "selected=\"selected\"";} ?>>Association</option>
      <option value="entreprise" <?php if (!(strcmp("entreprise", $_GET['activite']))) {echo "selected=\"selected\"";} ?>>Entreprise</option>
    </select>
    </form> 
     
     
    <?php if($_GET['activite'] == "particulier") { ?>
    <form method="post" action="">
         <label><strong>Nom particulier:</strong></label> <input type="text" name="nom_particulier"/><br/>
         <label><strong>Adresse particulier:</strong></label> <input type="text" name="adresse_particulier"/><br/>
         <label><strong>Code Postal particulier:</strong></label> <input type="text" name="code_particulier"/><br/>
         <label><strong>Ville particulier:</strong></label> <input type="text" name="ville_particulier"/><br/>
         <label><strong>Secteur d'activité particulier:</strong></label> <input type="text" name="activite_particulier"/><br/>
         <label><strong>Type de société particulier:</strong></label> <select name="type_particulier">
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
         </select>
    </form>
    <?php } ?> 
     
    <?php if($_GET['activite'] == "association") { ?>
    <form method="post" action="">
         <label><strong>Nom assoc:</strong></label> <input type="text" name="nom_association"/><br/>
         <label><strong>Adresse assoc:</strong></label> <input type="text" name="adresse_association"/><br/>
         <label><strong>Code Postal assoc:</strong></label> <input type="text" name="code_association"/><br/>
         <label><strong>Ville assoc:</strong></label> <input type="text" name="ville_association"/><br/>
         <label><strong>Secteur d'activité assoc:</strong></label> <input type="text" name="activite_association"/><br/>
         <label><strong>Type de société assoc:</strong></label> <select name="type_association">
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
         </select>
    </form>
    <?php } ?> 
     
    <?php if($_GET['activite'] == "entreprise") { ?>
    <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>
    <?php } ?>
    </body>
    </html>

  16. #16
    Membre averti 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
    Points : 394
    Points
    394
    Par défaut
    Citation Envoyé par debutantasp Voir le message
    Salut,
    Au premier chargement de la page l'élément afficher dans la liste sera "Particulier" mais son formulaire ne va pas s'afficher, pour l'afficher mets ça dans la balise body <body onload="affiche_formulaire()"> sinon tu laisses le premier élément de la liste vide ou bien tu mets un titre du genre "selectionner une activité" mais dans ce cas la du dois faire des modifications sur ta fonction.
    A+
    salut
    une simple modification au niveau de formulaire pour PARTICULIER fera affaire, pas besoin de chargement de la page ?.?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <!-- Particulier -->
    <span id="form_particulier" style="visibility:visible">
    a+

  17. #17
    Membre expérimenté
    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
    Points : 1 595
    Points
    1 595
    Par défaut
    La solution que j'indique en PHP est une alternative du problème d'affichage des formulaires avec les blancs dû aux spans cachés comme tu l'as indiqué ... et malheuresement cela entraine le rafraichissement de la page.

  18. #18
    Membre averti 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
    Points : 394
    Points
    394
    Par défaut
    c'est considérable, mais je préfèrerais utiliser innerHTML ou la construction dynamique.
    sinon le dernier post est adressé à debutantasp pour le problème d'affichage du formulaire PARTICULIER au démarrage.

    A+

  19. #19
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 15
    Points : 1
    Points
    1
    Par défaut
    Oula merci beaucoup de vous donner tout ce mal pour mon petit problème mais en fait il n'y en a pas car je ne veux pas faire de formulaire a part pour l'option "particulier" donc il n'y a pas de soucis...

    En réalité j'ai en fait un autre petit quelque chose qui me tracasse depuis ce matin...
    Dans les formulaires spécifiques "form_association" et "form_entreprise" je demande les types et j'en propose 3 dans un select...+ une otpion "autre"...
    Seulement mon ultime souhait serait d'afficher un "input, text" à coté si le visiteur sélectionne "autre"...

    Voila j'ai essayé pas mal de trucs(mais évidemment ça ne marche pas).J'ai essayé de créer une autre fonction "affiche_autre", de mettre mes 2 "If/else" dans la meme fonction "affiche formulaire" sans succès...Je me demande aussi si il ne faudrait pas verifier si le visiteur a auparavant choisi les options "entreprise" ou "association"...

    Voila donc je vous met une de ces versions de mon code ici, si quelqu'un trouve mon erreur je suis encore preneur...

    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
    <!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_formulaire() {
     
    // Association
    if (document.votre_activite.activite.selectedIndex == 1)
    document.getElementById('form_association').style.visibility = 'visible';
    else
    document.getElementById('form_association').style.visibility = 'hidden';
     
    // Entreprise
    if (document.votre_activite.activite.selectedIndex == 2)
    document.getElementById('form_entreprise').style.visibility = 'visible';
    else
    document.getElementById('form_entreprise').style.visibility = 'hidden';
    }
     
    function affiche_autre() {
     
    if (document.form_entreprise.type_entreprise.selectedIndex == 3)
    document.getElementById('autre_entreprise').style.visibility = 'visible';
    else
    document.getElementById('autre_entreprise').style.visibility = 'hidden';
     
    if (document.form_association.type_association.selectedIndex == 2)
    document.getElementById('autre_association').style.visibility = 'visible';
    else
    document.getElementById('autre_association').style.visibility = 'hidden';
    }
     
    </script>
     
    </head>
     
    <body>
     
    <form name="votre_activite" action="" method="post">
     
    <label><strong>Votre activité :</strong></label> <select name="activite" OnChange="affiche_formulaire();">
     
      <option name= value="particulier">Particulier</option>
      <option value="association">Association</option>
      <option value="entreprise">Entreprise</option>
                                                     </select>
        <br/>
    </form>
     
    <div 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" OnChange="affiche_autre();">
     
            <option value="pme">P.M.E</option>
            <option value="sa">S.A</option>
            <option name="sarl">S.A.R.L</option>
            <option name="autre">Autre</option>
         </select>
     
         <div id="autre_entreprise" style="visibility:hidden>"<label><strong>Indiquez le type de votre société :</strong></label> <input type="text" name="autre_type_entreprise">
         </div>
    </form>
    </div>
     
    <div id="form_association" style="visibility:hidden">
     
         <form method="post" action="">
     
          <label><strong>Nom :</strong></label> <input type="text" name="nom_association"/><br/>
     
          <label><strong>Type d'association</strong></label> <select name="type_association" OnChange="affiche_autre();">
     
          <option value="sportive">Sportive</option>
            <option value="politique">Politique</option>
            <option name="autre">Autre</option>
         </select>
         <div id="autre_association" style="visibility:hidden"><label><strong>Indiquez le type de votre association :</strong></label> <input type="text" name="autre_type_association"> 
         </div>
     
          <br/>
     
          <label><strong>But, Activité</strong></label> <input type="text" name="activite_association"/><br/>
     
        </form>
     
    </div>
     
    </body>
    </html>
    Le problème doit bel et bien venir de ma fonction car le formulaire est bien caché mais le reste aussi lorsque je sélectionne l'option "autre"....

    Voila, merci d'avance

  20. #20
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    381
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Maroc

    Informations forums :
    Inscription : Novembre 2007
    Messages : 381
    Points : 180
    Points
    180
    Par défaut
    Salut,
    Déjà je ne vois pas l'utilité de mettre un formulaire pour chaque activité, parce que les champs sont les mêmes dans chaque activité. Alors tu mets juste un seul formulaire mais au lieu d'écrire Nom Particulier ou bien Nom assoc tu mets juste Nom et tu fais pareil pour les autres, et tu récupère l'activité qui est marquée sur la liste pour les différencier.

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