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
|
<?php session_start();?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Manipulation des listes de choix</title>
</head>
<script type='text/javascript' src='oXHR.js'></script>
<script type='text/javascript'>
var xhr=null;
function request(callback)
{
xhr=getXHR();
if(xhr.readyState != 0)
{
xhr.abort();
}
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
callback(xhr.responseXML);
document.getElementById("loader").style.display = "none";
} else if (xhr.readyState < 4) {
document.getElementById("loader").style.display = "inline";
}
};
var value = encodeURIComponent(document.getElementById('editorsSelect').options[document.getElementById('editorsSelect').selectedIndex].value);
xhr.open("POST", "reqListe.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("IdEditor=" + value);
}
function test(sData)
{
var p = sData.getElementsByTagName("soft");
alert(p.length);
for(var i=0;i<p.length;i++)
{
var option = document.createElement("option");
var text = document.createTextNode(p[i].getAttribute('name'));
option.setAttribute('value',p[i].getAttribute('id'));
option.appendChild(text);
document.getElementById('softwaresSelect').appendChild(option);
}
}
</script>
<body>
<div id="programBox">
<p id="editors">
<select id="editorsSelect" onchange="request(test);">
<option value="none">Selection</option>
<?php
$bdd= new PDO('mysql:host=localhost;dbname=test','root','');
$reponse=$bdd->query('SELECT * FROM ajax_example_editors ORDER BY name') or die(print_r($bdd->errorInfo()));
while($rep=$reponse->fetch()) {
echo "\t\t\t\t<option value=\"" . $rep["id"] . "\">" . $rep["name"] . "</option>\n";
}
$reponse->closeCursor();
?>
</select>
<span id="loader" style="display: none;"><img src="loading.gif" alt="loading" /></span>
</p>
<p id="softwares">
<select id="softwaresSelect"></select>
</p>
</div>
</body>
</html> |