Bonjour,
Avant tout je dois vous dire que j'ai parcouru pas mal de forum et j'ai eu l'aide de personne qui connaissent l'ajax mais rien n'y fait!
Mon but :
J'ai un tableau avec une liste d�roulante et des champs input type="Text"
Je voudrais que lorsque l'utilisateur choisit une option dans le select, une information en rapport avec avec cette option s'affiche dans mon input (j'ai besoin d'un input car je le r�utilise apr�s)
Exemple : il choisit une firme dans la liste d�roulante et le num�ro de client de cette firme apparait dans le champs de texte.
Et bien sur si je suis ici c'est que �a ne marche pas (^.^)"
Mon ajax :
Mon php :
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 <script type="text/javascript"> function getXMLHttpRequest(){ var xhr = null; if (window.XMLHttpRequest || window.ActiveXObject) { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { xhr = new XMLHttpRequest(); } } else { alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest..."); return null; } return xhr; } function request1(callback) { var xhr = getXMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { callback(xhr.responseText); } }; var firme = encodeURIComponent(document.second.firme1.value); xhr.open("GET", "getuser.php?firme="+firme, true); xhr.send(null); } function readData1(sData){ document.getElementsByName("client1").innerHTML= sData; } </script>
Le <?php echo $i; ?> me sert car je fais une boucle pour afficher plusieurs fois le choix. (c'est aussi pourquoi ma fonction en js s'appelle 1, j'en ai 9 autres pareilles faite � la main pour juste changer le num�ro)
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 <form METHOD="POST" name="second" action="essai.php"> <?php $i=1; while($i<10){ ?> <tr> <td><input type=TEXT name="date<?php echo $i; ?>" style="width:40px;" value="<?php if(isset($_POST['date'.$i])){ echo $_POST['date'.$i]; }else{ echo "";} ?>"/></td> <td><input type=TEXT name="localite<?php echo $i; ?>" style="width:70px;" value="<?php if(isset($_POST['localite'.$i])){ echo $_POST['localite'.$i]; }else{ echo "";} ?>"/></td> <td><input type=TEXT name="dep<?php echo $i; ?>" style="width:40px;" value="<?php if(isset($_POST['dep'.$i])){ echo $_POST['dep'.$i]; }else{ echo "";} ?>" /></td> <td> <select name="firme<?php echo $i; ?>" OnChange="javascript:request<?php echo $i; ?>(readData<?php echo $i; ?>());" > <option value=" ">Selectionnez une entreprise</option> <option value="essai1">essai1</option> <option value="essai2">essai2</option> </select> </td> <td><input type=TEXT name="responsable<?php echo $i; ?>" style="width:70px;" value="<?php if(isset($_POST['responsable'.$i])){ echo $_POST['responsable'.$i]; }else{ echo "";}?>"/></td> <td><input type=TEXT name="pros<?php echo $i; ?>" style="width:70px;" value="<?php if(isset($_POST['pros'.$i])){ echo $_POST['pros'.$i]; }else{ echo "";}?>"/></td> <td><input type=TEXT name="client<?php echo $i; ?>" style="width:70px;" value="" /></td> <td><input type=TEXT name="code<?php echo $i; ?>" style="width:70px;" value="" /></td> <td><input type=TEXT name="observation<?php echo $i; ?>" style="width:350px;" value="<?php if(isset($_POST['observation'.$i])){ echo $_POST['observation'.$i];}else{ echo "";} ?>"/></td> </tr>
Mon fichier getuser.php
Avec Dragonfly (equivalent de firebug sous Opera)il me met lorsque je choisis une option :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10 <?php if(isset($_GET["firme"])){ mysql_connect("localhost","root",""); mysql_select_db("essai"); $res = mysql_query("SELECT * FROM user WHERE firme=".$_GET["firme"].""); $row = mysql_fetch_array($res) echo $row['client']; } ?>
Uncaught exception: TypeError: 'callback' is not a function
Error thrown at line 27, column 3 in <anonymous function: xhr.onreadystatechange>() in http://localhost/gnagnagna/essai.php:
callback(xhr.responseText);
Si vous pouviez m'aider j'en serais tr�s heureux![]()
Partager