Well, sounds great but doesn't seem to work ;xI've made a small change, instead of "age" I've put a salary field. SELECTs
<body><form><select id="users"><option value="">Select a person:</option><option value="1">Lois Griffin</option><option value="2">Glenn Quagmire</option></select><select id="salary" onchange="showUser()"><option value="">Select salary</option><option value="2000">2000</option><option value="4000">4000</option></select></form><br /><div id="txtHint"><b>Person info will be listed here.</b></div></body>
showUser function
<script type="text/javascript">function showUser(){var user = document.getElementById("users").value;var salary = document.getElementById("salary").value; if (salary=="") { document.getElementById("txtHint").innerHTML=""; return; }if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","getuser.php?q="+user"&s="+salary,true);xmlhttp.send();}</script>
and of course my .php file which works fine (I double checked ;P)
<?php$q=$_GET["q"];$s=$_GET["s"];$con = mysql_connect('localhost', 'root', '');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("ajax_demo", $con);$sql="SELECT * FROM user WHERE id = '".$q."' AND salary = '".$s."'";$result = mysql_query($sql);echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th><th>Age</th><th>Hometown</th><th>Job</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "<td>" . $row['Hometown'] . "</td>"; echo "<td>" . $row['Job'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?>
Must have done something wrong again