Bonjour,
J'ai une liste déroulante alimentée par une requête SQL, et à côté, les champs d'un formulaire
J'aimerais, dès que je sélectionne un nom dans la liste, que les champs se remplissent avec les données correspondantes
Voici mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?include ("connection.php");?>
<link rel="StyleSheet" type="text/css" href="http://wsb.torop.net/css/style.css">
<style type="text/css">
A:VISITED,A:LINK,A:ACTIVE {
	font-family:arial;
	text-decoration:none;
	color:#FF3300;
}
A:HOVER {
	font-family:arial;
	text-decoration:underline;
	color:#FF3300;
}
</style>
 
<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 go(){
				var xhr = getXhr();
				// On défini ce qu'on va faire quand on aura la réponse
				xhr.onreadystatechange = function(){
					// 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){
						leselect = xhr.responseText;
						// On se sert de innerHTML pour rajouter les options a la liste
						document.getElementById('livre').innerHTML = leselect;
					}
				}
 
				// Ici on va voir comment faire du post
				xhr.open("POST","ajaxArticles.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
				sel = document.getElementById('article');
				idauteur = sel.options[sel.selectedIndex].value;
				xhr.send("idArticle="+idarticle);
			}
</script>
 
<form method='POST' action='liste3.php' class='txtBlanc'>
	<div align='center'>
		<input type='hidden' name='noArticle' value=''>
	</div>
	<br>
 
	<div width='100%'>
		<div style='text-align:right;float:left;width:45%;height:30px;margin:3px;'>
			Date :  
		</div>
 
		<div style='text-align:left;float:left;width:45%;height:30px;margin:3px;'>
			<input type='texte' name='date' style='width:65px' value='<?=$date=date(d.m.y);?>'>
		</div>
	</div>
 
	<div width='100%'>
 
<?php
connectMaBase();
?>
		<div style='text-align:right;float:left;width:45%;height:30px;margin:3px;'>
			Article :  
		</div>
		<div style='text-align:left;float:left;width:45%;height:30px;margin:3px;'>
			<select name='idArticle' id='' onchange='go()'  style='width:300px'><option value=''>Choisir un article</option>
				<?
				$resultat=mysql_query("select nomArticle from article order by noArticle") or die ("requète non executé");
				if (! $resultat) { echo "Erreur requete"; exit;} 
				while ($ligne=mysql_fetch_array($resultat))
				{
				?>
				<option><?= ''.$ligne['nomArticle'].'';?> </option>
				<?php
                                }
                                
                                if($liste1 != -1){ //si on a fait un choix
                                        //on refait une requette avec une condition
                                        $sql = "SELECT nomArticle, intituléArticle, descArticle, prixArticle FROM article WHERE idArticle='".$idArticle."'";
                                        $requete = mysql_query($sql);
 
                                echo $nomArticle; echo "<br>"
                                echo $intituleArticle; echo "<br>";
                                echo $descArticle; echo "<br>";
                                }
        mysql_close();
        ?>
			</select>
		</div>
	</div>
 
	<div id='identClient'>        
		<div width='100%'>
		<div style='text-align:right;float:left;width:45%;height:30px;margin:3px;'>
			Nom de l'article : 
		</div>
		<div style='text-align:left;float:left;width:45%;height:30px;margin:3px;'>
			<input type='text' name='nomArticle' value='<?=$ligne['nomArticle'];?>'  style='width:300px'>
		</div>
	</div>
 
	<div width='100%'>
		<div style='text-align:right;float:left;width:45%;height:30px;margin:3px;'>
			Intitulé : 
		</div>
		<div style='text-align:left;float:left;width:45%;height:30px;margin:3px;'>
			<input type='text' name='intituleArticle' value='<?=$donnees['intituléArticle'];?>'  style='width:300px'>
		</div>
	</div>
 
	<div width='100%'>
		<div style='text-align:right;float:left;width:45%;height:30px;margin:3px;'>
			Description : 
		</div>
		<div style='text-align:left;float:left;width:45%;height:30px;margin:3px;'>
			<TEXTAREA name='description' rows=4 style='width:300px'></TEXTAREA>
		</div>
	</div>
 
	<div width='100%'>
		<div style='text-align:right;float:left;width:45%;height:30px;margin:3px;'>
			Montant : 
		</div>
		<div style='text-align:left;float:left;width:45%;height:30px;margin:3px;'>
			<input type='text' name='prix' id='' value='' onChange='totalFacture()'  style='width:40px;text-align:right;'> &euro;
		</div>
		<input type="submit" name="enregistrer" value="Enregistrer">
	</div>
 
</form>
Merçi d'avance pour votre aide