Bonjour,

J'ai donc deux listes déroulantes dont les choix sont chargés depuis une Bdd : tout cela fonctionne sans problème.

Je voudrais maintenant y imbriquer une 3eme liste après le choix des deux premieres listes.

J'ai donc créé un formualire de ce type :
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
<form>
<label>Problème</label>
			<select name="glob" onChange='Choix(this.form)'>  
			<option>--Choix --</option>
			<? $res = mysql_query("SELECT DISTINCT global_mat FROM tableau_recap");
						while($row = mysql_fetch_assoc($res)){
							echo "<option value='".$row["global_mat"]."'>".$row["global_mat"]."</option>";
						}
			?>
			</select>
 
			<label>Type-Impact</label>			
			<select name="type" onChange='Choix1(this.form)'>
			<option>--Choix--</option>
			</select>
 
			<label>Complément</label>			
			<select name="opt" >
			<option>--Choix--</option>
			</select>
</form>
et mes fonctions js qui devraient remplir mes listes.

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
 
function Choix(form){
var txt=new Array();
var txt_nb=new Array();
 
i = form.glob.selectedIndex;
if (i==0){
	return;
	}
<?php
 
$res1 = mysql_query("SELECT DISTINCT global_mat FROM tableau_recap");
$cpt_glob=0;
while($row1 = mysql_fetch_assoc($res1)){
        $cpt_glob++;
        $sel = mysql_query("SELECT DISTINCT type_pb FROM tableau_recap where global_mat='".$row1["global_mat"]."' ORDER BY 1");
        $cp=0;
        while($sel1 = mysql_fetch_assoc($sel)){
                $cp++;
                if ($cp==1) echo "txt[".$cpt_glob."]=new Array();";
                echo "txt[".$cpt_glob."][".$cp."]='".$sel1["type_pb"]."';";
                        
        }
        echo "txt_nb[".$cpt_glob."]=".$cp.";";
}
 
 
?>
 
form.type.options.length = 0;
form.type.selectedIndex = 0 ;
 
form.type.options[0]=new Option("--Choix--",0);
for(c=1;c<=txt_nb[i];c++) {
	form.type.options[c]=new Option(txt[i][c],txt[i][c]);
	}
}
et

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
var txt=new Array();
var txt_nb=new Array();
var txt_rb=new Array();
 
 
i = form.glob.selectedIndex;
if (i==0){
	return;
	}
<?php
 
 
$res1 = mysql_query("SELECT DISTINCT global_mat FROM tableau_recap");
$cpt_glob=0;
while($row1 = mysql_fetch_assoc($res1)){
        $cpt_glob++;
        $sel = mysql_query("SELECT DISTINCT type_pb FROM tableau_recap where global_mat='".$row1["global_mat"]."' ORDER BY 1");
        $cp=0;
        while($sel1 = mysql_fetch_assoc($sel)){
                $cp++;
                if ($cp==1) echo "txt[".$cpt_glob."]=new Array();";
                echo "txt[".$cpt_glob."][".$cp."]='".$sel1["type_pb"]."';";
                $cpbis=0;       
                $sel2 = mysql_query("SELECT DISTINCT optionnel FROM tableau_recap where global_mat='".$row1["global_mat"]."' and type_pb='".$sel1["type_pb"]."' ORDER BY 1");
                while($sel3 = mysql_fetch_assoc($sel2)){
                        $cpbis++;
                        if ($cpbis==1) echo "txt_nb[".$cp."]=new Array();";
                        echo "txt_nb[".$cp."][".$cpbis."]='".$sel3["optionnel"]."';";   
                        }
                }
                //echo "txt_nb[".$cpt_glob."]=".$cp.";";
                echo "txt_rb[".$cp."]=".$cpbis.";";
        }
 
?>
 
form.opt.options.length = 0;
form.opt.selectedIndex = 0 ;
 
form.opt.options[0]=new Option("--Choix--",0);
for(c=1;c<=txt_rb[i];c++) {
	form.opt.options[c]=new Option(txt_nb[i][c],txt_nb[i][c]);
	}
}
Pour le cas de deux listes, je n'appelle donc que Choix et j'enleve la selection <label>Complement</label> dans mon formulaire. Si je rajoute Choix1, seule la premeire selection (faite dans le formulaire) fonctionne.

Comme vous pouvez le voir, j'utilise un tableau afin de lister ma bdd puis je remplis ma liste déroulante. Malheureusement, je n'arrive pas à le faire fonctionner et je ne vois pas ou est mon problème.

Est-ce du au fait que je tente de remplir un tableau [2][2] pour quelque chose avec 3 requetes ? Pourtant, il semble avoir bien crée un autre tableau.

Quelq'un aurait il une idée ?

Merci.