/** * version utilisant une requête xmlhttp */ <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> /** * version n'utilisant pas de requête xmlhttp */ <?php $aTab = array (1 => array ('test', 'pour', 'une', 'blonde'), 2 => array ('difficile', 'ca?', 'non...'), 3 => array ('très', 'facile', 'en', 'fait!')); ?> <form method="post" id="mainForm"> <select name="liste1" onchange="document.getElementById('mainForm').submit();"> <?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>
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.