我现在正在使用下面的代码,我想显示rfq列表取决于rfq#。但是当我选择时,$ q是未定义的。
Dropdown.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时,该值是UNDEFINED。那是为什么?
这是脚本
<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>
答案 0 :(得分:0)
将this.value
传递给您的函数调用
<select name="users" onchange="showUser(this.value)">
<option value="ALL">ALL</option>
<?php echo $option; ?>
</select>
最新更新:
我想你想要链接这个
<html>
<script type="text/javascript">
function show() {
var e = document.getElementById('myOption');
var str = e.options[e.selectedIndex].text;
alert(str);
if(str=='All')
{
var x = document.getElementById("myOption");
var txt = "";
var i;
for (i = 1; i < x.length; i++) {
txt = txt + "," + x.options[i].text;
}
}
else{
txt=str;
}
alert(txt);
}
</script>
<body onload="show();">
<form name="myForm">
<select name="myOption" id="myOption" onChange="show()">
<option value="All" >All</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</form>
</body>
</html>
小提琴DEMO