Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1722 connectés 

  FORUM HardWare.fr
  Programmation

  [DHTML] reponse a funwebmax : interaction entre deux listes

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[DHTML] reponse a funwebmax : interaction entre deux listes

n°26229
darkoli
Le Petit Dinosaure Bleu
Posté le 20-04-2001 à 14:56:32  profilanswer
 

dans la page html qui suit lorsque la selection change dans la premiere liste, le contenu de la deuxieme liste est effacé puis remplacé par un nouveau contenu en fonction de la selection de la premiere liste.
 
testé sur ie5.
 

Code :
  1. <html>
  2. <head>
  3.   <title>Liste deroulantes</title>
  4.   <style>
  5.     select{font-family:courier new}
  6.     form{margin-top:0em}
  7.   </style>
  8. </head>
  9. <body>
  10. <script language="javascript">
  11.   var na=0;
  12.   var ta=new Array();
  13.   var nb=0;
  14.   var tb=new Array();
  15.   var nbm=0;
  16.   function ea(i,t) {
  17.     this.id=i;
  18.     this.texte=t;
  19.     this.taille=0;
  20.     }
  21.   function eb(a,i,t) {
  22.     this.ida=a;
  23.     this.id=i;
  24.     this.texte=t;
  25.     ta[a].taille=ta[a].taille+1;
  26.     if (ta[a].taille>nbm) nbm=ta[a].taille;
  27.     }
  28.   function aa(i,t) {
  29.     ta[na]=new ea(i,t);
  30.     na++;
  31.     }
  32.   function ab(a,i,t) {
  33.     tb[nb]=new eb(a,i,t);
  34.     nb++;
  35.     }
  36.   function ia() {
  37.     var s="";
  38.     for (var i=0;i<na;i++) {
  39.       s=s+"<option value=\""+ta[i].id+"\">"+ta[i].texte+"</option>";
  40.       }
  41.     return(s);
  42.     }
  43.   function ib() {
  44.     var s="";
  45.     for (var i=0;i<nb;i++) {
  46.       if (ta[0].id==tb[i].ida) {
  47.         s=s+"<option value=\""+tb[i].id+"\">"+tb[i].texte+"</option>";
  48.         }
  49.       }
  50.     for (var i=ta[0].taille;i<nbm;i++) {
  51.       s=s+"<option value=\"x\"></option>";
  52.       }
  53.     return(s);
  54.     }
  55.   function ca() {
  56.     var n=document.all.liste_a.options[document.all.liste_a.selectedIndex].value;
  57.     var nc=0;
  58.     for (var i=0;i<nbm;i++) {
  59.       document.all.liste_b.options[i].value="x";
  60.       document.all.liste_b.options[i].text="";
  61.       }
  62.     for (var i=0;i<nb;i++) {
  63.       if (n==tb[i].ida) {
  64.         document.all.liste_b.options[nc].value=tb[i].id;
  65.         document.all.liste_b.options[nc].text=tb[i].texte;
  66.         nc++;
  67.         }
  68.       }
  69.     }
  70.   aa(0,"ville" );
  71.   aa(1,"region" );
  72.   aa(2,"pays" );
  73.   ab(0,0,"montbeliard" );
  74.   ab(0,1,"belfort" );
  75.   ab(0,2,"paris" );
  76.   ab(1,0,"franche comté" );
  77.   ab(1,1,"ile de france" );
  78.   ab(2,0,"france" );
  79.   ab(2,1,"italie" );
  80.   ab(2,2,"espagne" );
  81.   ab(2,3,"danemark" );
  82. </script>
  83. <select name="liste_a" onChange="ca()"><script language="javascript">document.write(ia())</script></select>
  84. <select name="liste_b" ><script language="javascript">document.write(ib())</script></select>
  85. </body>
  86. </html>

mood
Publicité
Posté le 20-04-2001 à 14:56:32  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [DHTML] reponse a funwebmax : interaction entre deux listes

 

Sujets relatifs
[DHTML] reponse a funwebmax : transfert entre deux listesDHTML avec netscape
[DHTML] Performance : IFRAME ou DIV (LAYER) ?[DHTML] : div
[DHTML Drag & Drop] pour ceux qui posent toujours des questions[HTML et DHTML et Javascript] pour ceux qui posent plein de questions
[DHTML & ie] layer 
Plus de sujets relatifs à : [DHTML] reponse a funwebmax : interaction entre deux listes


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR