I am trying to have 2 separate divs with one labeled Email and the 2nd div named Number. When a user chooses a person from drop down the retrieved info from PHP + MySQL should be added in a div just how it gets added to the div when you click add at: http://jsfiddle.net/QVUHU/84/
I am stuck because I dont know how to add the retrieved info into 2 divs one for email one for number like the one at js fiddle...
Below is my html + ajax and PHP code
HTML + AJAX
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
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="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Achau</option>
<option value="2">Ravi</option>
<option value="3">Justin</option>
</select>
</form>
<br />
<div id="txtHint">
<b><table>
<tr>
<th>Email</th>
<th>Number</th>
</tr></b></div>
</body>
</html>
PHP + MySQL
<?php
$q=$_GET["q"];
$con = mysql_connect("tghbdfg1","Userbhgins","Jpgbhfw3");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("UserLogins", $con);
$sql="SELECT * FROM PersonInfo WHERE id = '".$q."'";
$result = mysql_query($sql);
echo " <br />";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['PNumber'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
bandbrtags.