Bonjour,
Voilà je but depuis un petit moment sur un petit soucis...
Je voulais faire 3 listes déroulantes, la 1ère va généré le contenu et afficher le <select> de la 2nd liste, la 2nd génère le contenu et affiche le <select> de la 3ème, jusqu'ici c'est cool
Mais quand je rechange le choix sur la première liste, la seconde est bien généré, mais la 3ème ne se rafraichis pas et reste donc avec la suite de choix précédent et n'est pas "caché".
Donc s'est pas très fonctionnel...
Bref voici le code :
Partie HTML
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 <form action="" method="post"> <table> <tr> <td>Country: </td> <td><select id="dhtmlgoodies_country" name="dhtmlgoodies_country" onchange="getStateList(this)"> <option>Any</option> <?php $sql = 'SELECT * FROM pays ORDER BY pays_int'; $query = mysql_query($sql) or die( 'Erreur' ); while ( $g = mysql_fetch_array( $query )) { echo '<option value="'.$g['id_pays'].'">'.$g['pays_int'].'</option>'; } ?> </select> </td> </tr> <tr id="dhtml_state" style="display:none"> <td>State:</td> <td><select id="dhtmlgoodies_state" name="dhtmlgoodies_state" onchange="getCityList(this)"></select></td> </tr> <tr id="dhtml_city" style="display:none"> <td>City: </td> <td><select id="dhtmlgoodies_city" name="dhtmlgoodies_city"></select></td> </tr> </table> </form>
Partie JS
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 function getStateList(sel) { var countryCode = sel.options[sel.selectedIndex].value; var sel_state = document.getElementById('dhtmlgoodies_state'); sel_state.options.length = 0; // Empty city select box if(countryCode.length>0){ document.getElementById('dhtml_state').style.display = ""; var index = ajax.length; ajax[index] = new sack(); ajax[index].requestFile = 'getCities.php?countryCode=' + countryCode; // Specifying which file to get ajax[index].onCompletion = function(){ createState(index) }; // Specify function that will be executed after file has been found ajax[index].runAJAX(); // Execute AJAX function } } function getCityList(sel) { var stateCode = sel.options[sel.selectedIndex].value; var sel_city = document.getElementById('dhtmlgoodies_city'); sel_city.options.length = 0; // Empty city select box if(stateCode.length>0){ document.getElementById('dhtml_city').style.display = ""; var index = ajax.length; ajax[index] = new sack(); ajax[index].requestFile = 'getCities.php?stateCode=' + stateCode; // Specifying which file to get ajax[index].onCompletion = function(){ createCities(index) }; // Specify function that will be executed after file has been found ajax[index].runAJAX(); // Execute AJAX function } } function createState(index) { var obj = document.getElementById('dhtmlgoodies_state'); eval(ajax[index].response); // Executing the response from Ajax as Javascript code } function createCities(index) { var obj = document.getElementById('dhtmlgoodies_city'); eval(ajax[index].response); // Executing the response from Ajax as Javascript code }
Bref si quelqu'un pourrait m'éclaircir les idées serait le très bien venu![]()
Partager