Les LAYER et DIV : peux ton cacher TYPE=TEXT

nicolas -  
PhP Messages postés 1774 Statut Membre -
Question DHTML

Je souhaiterai faire un formulaire et si dans une liste a 2 choix

-je selectionne "1" je veux cacher <INPUT TYPE=TEXT NAME="CHOIX">
-je selectionne "2" je veux afficher <INPUT TYPE=TEXT NAME="CHOIX"> (complement d'infos)

est-ce possible ?
merci

2 réponses

  1. PhP Messages postés 1774 Statut Membre 606
     
    Bonsoir Nicolas,

    C'eest en effet possible, tout au moins avec Internet Explorer 5 ou +

    Voici un ex :

    <script language="JavaScript">
    <!--

    function choix()
    {
    idx=document.frmTest.lstChoix.selectedIndex;
    if (idx==-1) return false;

    // Retrouve la référence au layer divCpl dans le modèle DOM
    ref=window.document.getElementById("divCpl");
    if (idx==0)
    {
    afficheCpl(false);
    }
    else
    {
    afficheCpl(true);
    }
    }

    // Si visible=true alors l'élément est affiché
    // si visible=false alors l'élément est masqué
    function afficheCpl(visible)
    {
    ref=window.document.getElementById("divCpl");
    ref.style.visibility=(visible) ? "visible":"hidden";
    }

    function load()
    {
    // Sélectionne le 1er élément dans le liste
    document.frmTest.lstChoix.selectedIndex=0;
    // Puis affiche ou masque la zone complément
    choix()
    }

    // -->
    </script>

    </head>
    <body onload="load()">
    <form name="frmTest" method="POST" action="p2.htm">
    <fieldset><legend>Le formulaire (seul le choix 2 affiche la zone complément)</legend>
    <table>
    <tr>
    <td>
    <select name="lstChoix" size="2" onchange="choix()">
    <option value="1">Choix 1</option>
    <option value="2">Choix 2</option>
    </select>
    </td>
    <td>
    <div id="divCpl">Complément : <input type="text" value="" name="complement">
    </div>
    </td>
    </tr>
    </table>
    </fieldset>
    </form>
    </body>
    </html>

    Et voilà ! ;-)

    @+
    Philippe

    [[  The Truth is Out There   ]]
    0
  2. PhP Messages postés 1774 Statut Membre 606
     
    Ooops !!

    Avant la balise <script language ...>

    il manque un truc du genre :

    <html>
    <head>
    <title>Cache-cache IE 5 ou + seulement !</title>

    Mais tu auras rectifié par toi même ...

    Bye

    [[  The Truth is Out There   ]]
    0