我现在使用下面的代码,我想显示 rfq 列表取决于 rfq #。但是当我选择时, $q 是未定义的。
下拉列表.php
<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("app",$con);
$get=mysql_query("SELECT rfq FROM procurement GROUP BY rfq ORDER BY rfq");
$option = '';
while($rows = mysql_fetch_assoc($get))
{
$option .= '<option value = "'.$rows['rfq'].'">'.$rows['rfq'].'</option>';
}
?>
<form>
<select name="users" onchange="showUser()">
<option value="ALL">ALL</option>
<?php echo $option; ?>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
getuser.php
<?php
include('connect.php');
$q=$_GET["q"];
$sql="SELECT rfq FROM procurement WHERE rfq='".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>MOD</th>
<th>RFQ #</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['mode_of_procurement']."</td>";
echo "<td>".$row['rfq']."</td>";
echo "</tr>";
}
echo "</table>";
echo $q;
mysql_close();
?>
但是没有显示 $q 的值,当我回显 $q 时,该值是未定义的。这是为什么?
这是脚本
<script>
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>