1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| function request(oSelect)
{
var value = oSelect.options[oSelect.selectedIndex].value;
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
//alert(xhr.responseText);
var monXml=xhr.responseXML;
readData(monXml);
}
};
xhr.open("POST", "Ajax.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("Departement=" + value);
}
function readData(oData)
{
var nodes = oData.getElementsByTagName("noeud");
for (var i=0; i<nodes.length;i++) {
leId = nodes[i].getElementsByTagName("numero")[0].firstChild.nodeValue;
leNom = nodes[i].getElementsByTagName("lenom")[0].firstChild.nodeValue;
var code = leNom;
monOption = document.createElement("option");// on creer une balise
monOption.value = leId;// on modifie son parametre value
monOption.innerHTML = code; //On injecte le code html a la balise
document.getElementById("Ville").appendChild(monOption);// on incorpore la balise <option> au <select>
}
} |