3 Liste déroulante en chaine qui se Masque/Démasque les une aux autres
scoal
Messages postés78Date d'inscriptiondimanche 3 juillet 2005StatutMembreDernière intervention 8 avril 2012
-
28 juil. 2009 à 21:43
mrpropre57
Messages postés8Date d'inscriptionvendredi 27 août 2004StatutMembreDernière intervention16 avril 2014
-
13 nov. 2012 à 14:54
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
<form action= "" method="post">
Country:,
<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>,
----
State:,
<select id="dhtmlgoodies_state" name="dhtmlgoodies_state" onchange="getCityList(this)"></select>,
----
City:,
<select id="dhtmlgoodies_city" name="dhtmlgoodies_city"></select>
</form>
Partie JS
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
A voir également:
3 Liste déroulante en chaine qui se Masque/Démasque les une aux autres