Voila le code ke le stagiere avant moi a créé, mais il y a un probleme car lorske la liste affiche les nom ki komence par se ke lutilisateur a saisit je ne pe pa selectionner le nom que je veut et j'aimerais savoir pk merci :
<HTML>
<HEAD>
<TITLE>Affichage</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// D'autres scripts et des tutoriaux sur http://www.toutjavascript.com
// Script développé par Tout JavaScript.com
// Si vous utilisez ce script, merci de laisser ce commentaire
var Liste=new CreerListe("Noms", 5, 200)
<?php
// Connecxion a ta base de donnée
$db = mysql_connect('localhost', 'root', '');
//choix de la table
mysql_select_db('bddtest',$db);
//Requete
$sql = "SELECT nom FROM annuaire where nom is not null Group by nom ORDER BY nom";
$res = mysql_query($sql);
//Test de la requete
if(!$res)
{
echo'Requete impossible';
}
else
{
while($rep = mysql_fetch_assoc($res))
{
if($rep['nom'] != '')
{
echo 'Liste.Add("'.$rep['nom'].'" );';
}
}
}
?>
function CreerListe(nom, hauteur, largeur)
{
this.nom=nom; this.hauteur=hauteur; this.largeur=largeur;
this.search="";
this.nb=0;
this.Add=AjouterItem;
this.Afficher=AfficherListe;
this.MAJ=MAJListe;
}
function AjouterItem(item)
{
this[this.nb]=item
this.nb++;
}
function AfficherListe() {
var Z = '<select name="' + this.nom + '" size="' + this.hauteur + '" onchange="this.form.elements[\'search\'].value="'+ this.value + '">';
for (var i=0; i<this.nb; i++) {
Z+="<option value=\""+this[i]+"\">"+this[i]+"</option>"
}
Z+="</select>"
document.write(Z);
}
function MAJListe(txt,f)
{
if (txt!=this.search)
{
this.search=txt
f.elements[this.nom].options.length=0;
for (var i=0; i<this.nb; i++)
{
if ( this[i].substring(0,txt.length).toUpperCase()==txt.toUpperCase() )
{
var o=new Option(this[i], this[i]);
f.elements[this.nom].options[f.elements[this.nom].options.length]=o;
}
}
if (f.elements[this.nom].options.length==1)
{
f.elements[this.nom].selectedIndex=0;
}
}
}
function ListeCheck()
{
Liste.MAJ(document.forms["affichLettre"].search.value,document.forms["affichLettre"])
if (document.layers)
{
setTimeout("ListeCheck()", 1001)
}
else
{
setTimeout("ListeCheck()", 100)
}
}
function Selecte()
{
var objet;
objet=event.srcElement;
document.form.champ.value=objet.innerHTML;
}
function CreaCell()
{
var ligne, cellule;
ligne=liste.insertRow(); // Insère une ligne dans le tableau.
cellule=ligne.insertCell(); // Insère une cellule dans la ligne.
with (cellule)
{
noWrap=true; // Définit les propriétés
style.cursor="default"; // et événements.
onclick=Selecte;
innerHTML=Liste[i]; // Insère le texte dans la cellule.
}
}
function Cherche()
{
var text, temp;
text=document.form.champ.value;
for (i=0;i<Liste.length;i++)
{
temp=Liste[i];
temp=temp.toLowerCase();
CreaCell(); // Crée un élément pour chaque occurrence trouvée.
}
cadre.style.visibility="visible";
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #FFFFCC;
}
-->
</style></HEAD>
<BODY>
<FONT FACE="Arial" SIZE='-1' COLOR="navy">
<BR>
<br>
<a href="annuaire.php" target="affichage"><font face="Cooper Black">retour a la page Annuaire</font></a></br>
<br>
<br>
<CENTER><BIG><B><font color="#993333" size="+2" face="Broadway">Ecrivez le nom de la personne recherchée :</font> </B></BIG><BR><BR></CENTER>
<!--on affiche une liste déroulante des noms et des prénoms-->
<FORM method="post" name="affichLettre" action="maListeTest.php">
<font face="Imprint MT Shadow">Nom :</font><INPUT type="text" name="search" id="search" value="<?php echo $nomRech = $_POST['nomRech']; ?>"/><BR>
<script language="javascript">
Liste.Afficher();
ListeCheck();
$nomRech;
</script>
<br>
<input type="submit" /><br>
</FORM>
<?php
include('connectRech.php');
?>
</BODY>
</HTML>