Hello all, I have a drop down that is populated using php and mysql. when the user makes a selection, I run the function showUser(), however, nothing happens when i make a selection, can anyone help with what I'm doing wrong?
The JS
<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>
The PHP script
<?php
//Include connection to database
require_once 'connect.php';
$q=$_GET["q"];
$sql="SELECT * FROM table WHERE id = '".$q."'";
$resultab = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>Kinase</th>
<th>Kinase Sku</th>
<th>Antibody</th>
<th>Antibody2</th>
<th>Tracer</th>
<th>Tracer Conc</th>
</tr>";
while($row = mysql_fetch_array($resultab))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['kinase'] . "</td>";
echo "<td>" . $row['kinase_sku'] . "</td>";
echo "<td>" . $row['antibody'] . "</td>";
echo "<td>" . $row['antibody2'] . "</td>";
echo "<td>" . $row['tracer'] . "</td>";
echo "<td>" . $row['tracer_conc'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
The HTML
<form action="" method="post">
<fieldset>
<!-- RUN QUERY TO POPULATE DROP DOWN -->
<?php
$query = "SELECT * FROM kbaCalc
ORDER by kinase";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result); //number of messages
while($row = mysql_fetch_array($result)) {
$kinase = $row['kinase'];
$tracer_conc = $row['tracer_conc'];
$options.= "<option value='$id'>".$kinase;
}
echo "</select>";
?>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a Kinase:</option>
<?=$options?>
</select>
<div id="txtHint">Stuff here!</div>
</fieldset>
</form>
If I make a normal html select dropdown, the script works, however, when I populate it using php, I get nothing.
Any help/advice would be awesome.