21,881
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script src="selectcustomer.js"></script>
</head>
<body>
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action="1.php">
请选择一位客户:
<select name="customers" onchange="showCustomer(this.value)">
<option value="1">123
<option value="2">sd
<option value="3">Wolski Zajazd
</select>
<select name="customers1" onchange="showCustomer2(this.value)">
<option value="1">123</option>
<option value="2">sd</option>
<option value="WOLZA">Wolski Zajazd</option>
</select>
</form>
<p>
<div id="txtHint"><b>客户信息将在此处列出。</b></div>
</p>
</body>
</html>
var xmlHttp
function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="getcustomer.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
<?php
$link = mysql_connect("localhost","root","123") or die("");
mysql_select_db("join_link",$link) or die("");
$sql = "select * from register where reg_id=".$_GET['q'];
$result = mysql_query($sql);
echo "<select>";
while($row=mysql_fetch_array($result))
{
echo "<option value='$row[id]'>".$row['reg_id']."</option>";
}
echo "</select>";
mysql_close($link);
?>