Réponse acceptée !
Hello,
un exemple avec xmlhttp.
Adaptable SANS.
<script type="text/javascript">
if (window.XMLHttpRequest) {
oXmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
oXmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function search (clef) {
oXmlhttp.open('POST','<?php echo $_SERVER['PHP_SELF']; ?>');
oXmlhttp.onreadystatechange=function() {
if (oXmlhttp.readyState==4 && oXmlhttp.status == 200) {
document.body.innerHTML = oXmlhttp.responseText;
}
}
oXmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var data = 'liste1='+clef
oXmlhttp.send (data);
}
</script>
<?php
$aTab = array (1 => array ('test', 'pour', 'une', 'blonde'),
2 => array ('difficile', 'ca?', 'non...'),
3 => array ('très', 'facile', 'en', 'fait!'));
?>
<form method="post">
<select name="liste1" onchange="search (this.value);">
<?php
foreach ($aTab as $clef => $dump) {
$selected=(isset($_POST['liste1']) && $_POST['liste1'] == $clef)?'selected="selected"':'';
echo '<option value="',$clef,'" ',$selected,'>',$clef,'</option>';
}
?>
</select>
<?php
if (isset ($_POST['liste1']) && !empty ($_POST['liste1'])) {
echo '<select name="liste2">';
foreach ($aTab[$_POST['liste1']] as $val) {
echo '<option value="',$val,'">',$val,'</option>';
}
echo '</select>';
}
?>
</form>