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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| <html>
<head>
<title>My webpage is rich</title>
<script type='text/javascript'>
function getXhr()
{
var xhr = null;
if(window.XMLHttpRequest)
{ // Firefox et autres
xhr = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{ // Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else
{
// XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xhr = false;
}
return xhr;
}
/**
* Méthode qui sera appelée sur le click du bouton
*/
function change()
{
var xhr = getXhr();
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function()
{
//alert(xhr.readyState);
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200)
{
di = document.getElementById('prenom');
di.innerHTML = xhr.responseText;
}
}
// Ici on va voir comment faire du post
xhr.open("POST","ajaxLivre.php",true);
// ne pas oublier ça pour le post
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
// ne pas oublier de poster les arguments
// ici, l'id de l'auteur
NomStg = document.getElementById('nom').options[document.getElementById('nom').selectedIndex].value;
//PrenomStg = document.getElementById('prenom').options[document.getElementById('prenom').selectedIndex].value;
//alert(NomStg);
xhr.send("Nom="+NomStg);
//xhr.send("Prenom="+PrenomStg);
}
function change2()
{
var xhr = getXhr();
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function()
{
//alert(xhr.readyState);
// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
if(xhr.readyState == 4 && xhr.status == 200)
{
di = document.getElementById('id_def');
di.innerHTML = xhr.responseText;
}
}
// Ici on va voir comment faire du post
xhr.open("POST","ajaxId_Def",true);
// ne pas oublier ça pour le post
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
// ne pas oublier de poster les arguments
// ici, l'id de l'auteur
//NomStg = document.getElementById('nom').options[document.getElementById('nom').selectedIndex].value;
PrenomStg = document.getElementById('prenom').options[document.getElementById('prenom').selectedIndex].value;
//alert(NomStg);
//xhr.send("Nom="+NomStg);
xhr.send("Prenom="+PrenomStg);
}
</script>
</head>
<body>
<form>
<fieldset style="width: 600px">
<legend>Liste liées</legend>
<label>Noms</label>
<select name='nom' id='nom' onchange='change()'>
<option value='-1'>Aucun</option>
<?php
mysql_connect("localhost","root","mysql");
mysql_select_db("cmfp_base_commune");
$res = mysql_query("SELECT Distinct Nom from Stagiaires ORDER BY Nom");
while($row = mysql_fetch_assoc($res))
{
echo "<option value='".$row["Nom"]."'>".$row["Nom"]."</option>";
}
?>
</select>
<label>Prenoms</label>
<div id='prenom' style='display:inline'>
<select name='prenom' id='prenom' onchange='change2()'>
<option value='-1'>Choisir un nom</option>
</select>
</div>
<label>Id_Def</label>
<div id='id_def' style='display:inline'>
<select name='id_def'>
<option value='-1'>Choisir un nom et un prenom</option>
</select>
</div>
</fieldset>
</form>
</body>
</html> |