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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../01_scripts/oXHR.js"></script>
<script type="text/javascript">
//function request(oSelect) {
//var value = oSelect.options[oSelect.selectedIndex].value;
function select_dept_from_cp(oInput) {
var cp = oInput.value;
console.log(cp);
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
readData(xhr.responseXML);
document.getElementById("loader").style.display = "none";
} else if (xhr.readyState < 4) {
document.getElementById("loader").style.display = "inline";
}
};
xhr.open("POST", "choixdepartement.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// xhr.send("departementId=" + value);
xhr.send("cp");
}
function readData(oData) {
var nodes = oData.getElementsByTagName("item");
var oSelect = document.getElementById("lst_departements");
var oOption, oInner;
oSelect.innerHTML = "";
for (var i=0, c=nodes.length; i<c; i++) {
oOption = document.createElement("option");
oInner = document.createTextNode(nodes[i].getAttribute("departementLibelle"));
oOption.value = nodes[i].getAttribute("departementId");
oOption.appendChild(oInner);
oSelect.appendChild(oOption);
}
}
//-->
</script>
</head>
<?php
include('../01_scripts/connexion.php');
?>
<body>
<?php
?>
<form id="cp" method="post" action="01_enreg_cp.php">
<table width="100%" border="1" cellspacing="1" cellpadding="0">
<tbody>
<tr>
<td>Code Postal</td>
<td><input type="text" name="cp" size="6" onBlur="select_dept_from_cp(cp);"></td>
</tr>
<tr>
<td>Le département </td>
<td><select id="lst_departements"></select></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="envoyer" value="Enregistrer"</td>
</tr>
</tbody>
</table>
</form>
</body>
</html> |
Partager