Bonjour,
Mon code fonctionne bien sauf pour récupérer les valeurs de ma liste déroulante.
Voici mon code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Listes déroulantes </title>
<script type="text/javascript">
var Ld1Id='';
var Ld2Id='';
var id_liste='';
function ValideLd2(val) {
Ld1Id=val; //id_département
id_liste='2';//Utilisé dans la fonction ChargeLd() pour identifier la liste déroulante
var LD_URL = 'ValideLd2.php?Ld1='+Ld1Id;
ObjetXHR(LD_URL)
// Réinitialisation de Ld3 si modification de LD1 après passage en Ld2
if (Ld2Id!='') {ValideLd3(''); }
}
function ValideLd3(val) {
Ld2Id=val; //id_commune
id_liste='3'; //Utilisé dans la fonction ChargeLd() pour identifier la liste déroulante
var LD_URL = 'ValideLd3.php?Ld1='+Ld1Id+'&Ld2='+Ld2Id;
if (Ld2Id=='') {var LD_URL = 'ValideLd3.php';}
ObjetXHR(LD_URL)
}
function ObjetXHR(LD_URL) {
//creation de l'objet XMLHttpRequest
if (window.XMLHttpRequest) { // Mozilla,...
xmlhttp=new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType('text/xml');
}
xmlhttp.onreadystatechange=ChargeLd;
xmlhttp.open("GET", LD_URL, true);
xmlhttp.send(null);
} else if (window.ActiveXObject) { //IE
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
if (xmlhttp) {
xmlhttp.onreadystatechange=ChargeLd;
xmlhttp.open('GET', LD_URL, false);
xmlhttp.send();
}
}
}
// fonction pour manipuler l'appel asynchrone
function ChargeLd() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
//span id="niv2" ou "niv3"
document.getElementById('niv'+id_liste).innerHTML=xmlhttp.responseText;
if (xmlhttp.responseText.indexOf('disabled')<=0) {
//focus sur liste déroulante 2 ou 3
document.getElementById('Liste'+id_liste).focus();
}
}
}
}
function addModele(){
if(document.cartouche.Liste3.options[document.cartouche.Liste3.selectedIndex].value != ''){
id= document.cartouche.Liste3.options[document.cartouche.Liste3.selectedIndex].value;
libelle= document.cartouche.Liste3.options[document.cartouche.Liste3.selectedIndex].text;
taille= document.cartouche.list_modeles.options.length;
opt= new Option(libelle,id,false,false);
document.cartouche.list_modeles.options[taille]= opt;
document.cartouche.Liste3.focus();
}else{
alert("Veuillez sélectionner un élément à ajouter");
}
}
function removeModele(){
if(document.cartouche.list_modeles.selectedIndex != -1)
document.cartouche.list_modeles.remove(document.cartouche.list_modeles.selectedIndex);
else{
alert("Veuillez sélectionner l'élément à supprimer");
}
}
</script>
</head>
<body>
<div id="Les3LD">
<form method="post" action="form.php" name="cartouche">
<p><?
include 'ValideLd1.php'; ?> <!--Pour remplir la liste déroulante 1-->
</p>
<p><span id="niv2">
<? include 'ValideLd2.php'; ?></span></p> <!--Pour remplir la liste déroulante 2-->
<p><span id="niv3">
<? include 'ValideLd3.php'; ?></span>
<input class="formulaire_red" value="+" onclick="addModele();" type="button">
<input class="formulaire_red" value="-" onclick="removeModele();" type="button">
</p>
<p><select name="list_modeles" id="list_modeles" size="8" multiple="multiple" style="width: 350px;">
</select>
</p>
<input type="submit" value="Valider" />
</form>
</div>
</body>
</html>
Merci d'avance