Bonjour @Yokil Désolé du retard ci joint le code complet qui fonctionne
Le code pour les régions
<?php
$serveur = "**";
$admin = "**";
$mdp = "**";
$base = "**";
$sql = "SELECT `id_region` AS idr, `region` ".
"FROM `region` ".
"ORDER BY `id_region`;";
$connexion = mysql_connect($serveur, $admin, $mdp);
if($connexion != false)
{
$choixbase = mysql_select_db($base, $connexion);
$recherche = mysql_query($sql, $connexion);
$regions = array();
$id = 0;
while($ligne = mysql_fetch_assoc($recherche))
{ $regions[$ligne['idr']] = $ligne['region']; } ?>
<select name="r" class="input_recherche22" id="region" onchange="getDepartements(this.value);">
<option value="" >Toute la France</option>
<?php
foreach($regions as $nr => $nom)
{
?>
<option value="<?php echo($nr); ?>" <?php if (!(strcmp($nr, htmlentities($_GET['r'], ENT_COMPAT, 'UTF-8')))) {echo "selected=selected";} ?>><?php echo($nom); ?></option>
<?php
}
?>
</select>
<span id="blocDepartements"></span>
<script type="text/javascript">
d = document.getElementById("region").value;
document.getElementById('region').attachEvent('onchange', getDepartements(d));
</script>
<?php } else { ?>
<?php } ?>
Le js
var requete = null;
function creerRequete()
{
try
{
requete = new XMLHttpRequest();
}
catch (microsoft)
{
try
{
requete = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(autremicrosoft)
{
try
{
requete = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(echec)
{
requete = null;
}
}
}
if(requete == null)
{
alert('Votre navigateur ne semble pas supporter.');
}
}
function actualiserDepartements()
{
var listeDept = requete.responseText;
var blocListe = document.getElementById('blocDepartements');
blocListe.innerHTML = listeDept;
}
function getParamValue(param,url)
{
var u = url == undefined ? document.location.href : url;
var reg = new RegExp('(\\?|&|^)'+param+'=(.*?)(&|$)');
matches = u.match(reg);
return (matches && matches[2] != undefined) ? decodeURIComponent(matches[2]).replace(/\+/g,' ') : '';
}
function getDepartements(idr)
{
if(idr == '')
{
document.getElementById('blocDepartements').innerHTML = '';
}
else
{
var blocListe = document.getElementById('blocDepartements');
blocListe.innerHTML = "";
creerRequete();
var url = 'js/departements_recherche22.php?idr='+ idr + '&d=' + (getParamValue('d'));;
requete.open('GET', url, true);
requete.onreadystatechange = function()
{
if(requete.readyState == 4)
{
if(requete.status == 200)
{
actualiserDepartements();
}
}
};
requete.send(null);
}
}
Le code pour afficher les départements
<?php
$serveur = "**";
$admin = "**";
$mdp = "**";
$base = "**";
$idr = isset($_GET['idr']) ? $_GET['idr'] : false;
if(false !== $idr)
{
$sql2 = "SELECT `id_departement`, `departement`, `dep`".
" FROM `departement`".
" WHERE `id_region` = ". $idr ."".
" ORDER BY `id_departement`;";
$connexion = mysql_connect($serveur, $admin, $mdp);
mysql_select_db($base, $connexion);
$rech_dept = mysql_query($sql2, $connexion);
$nd = 0;
$code_dept = array();
$nom_dept = array();
while(false != ($ligne_dept = mysql_fetch_assoc($rech_dept)))
{
$code_dept[] = $ligne_dept['id_departement'];
$nom_dept[] = $ligne_dept['departement'];
$codeid_dept[] = $ligne_dept['dep'];
$nd++;
}
$liste = "";
$liste .= '<select name="d" class="input_recherche22" id="departement"><option value="" >Tous les Départements</option>'."\n";
for($d = 0; $d < $nd; $d++)
{
$selected = "";
if($_GET['d'] == $code_dept[$d]) $selected = 'selected="selected"';
$liste .= '<option value="'. $code_dept[$d] .'" '.$selected.'>'. htmlentities($nom_dept[$d]).' ('. htmlentities($codeid_dept[$d]).')</option>'."\n";
unset($selected);
}
$liste .= '</select>'."\n";
mysql_free_result($rech_dept);
echo($liste);
}
else
{
echo("<p>Une erreur s'est produite.</p>\n");
}
?>