JS Liste déroul. en chaine qui se Masq/Démasq
scoal
Messages postés
78
Date d'inscription
Statut
Membre
Dernière intervention
-
Ozimandias Messages postés 505 Date d'inscription Statut Membre Dernière intervention -
Ozimandias Messages postés 505 Date d'inscription Statut Membre Dernière intervention -
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">
<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
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
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">
<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
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:
- JS Liste déroul. en chaine qui se Masq/Démasq
- Liste déroulante excel - Guide
- Liste déroulante en cascade - Guide
- Chaine tnt gratuite sur mobile - Guide
- Liste code ascii - Guide
- Chaine radio - Télécharger - Médias et Actualité