我使用 Ajax 和 abc.php(代码如下)来填充第二个选择标签的值,但我无法填充第三个选择标签,它应该出现在选择第二个选择标签之后。任何建议将不胜感激
<?php
$q=$_GET["q"];
include "localhost.php";
$sql="SELECT * FROM books WHERE class = '".$q."'";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo "<select name=\"name\">
<option>Select subject
</option>";
echo "<option>" . $row['name'] ."</option>";
echo "</select>";
}
}
else
{
echo "error";
}
mysql_close($con);
?>
我的html代码是
<?php
include "menu.php";
include "localhost.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
<!--Code for selecting class-->
function showUser(str)
{
if (str=="Select class:")
{
document.getElementById("txtHint").innerHTML="Select any class";
return;
}
if (str=="Select cla:")
{
document.getElementById("txtHint1").innerHTML="Select any cla";
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","select11.php?q="+str,true);
xmlhttp.send();
}
<!--End of Code for selecting class-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link type="text/css" href="style.css" rel="stylesheet" />
</head>
<body>
<div id="sn">
<ul class="crumbs">
<li class="first"><a href="iindex.php" style="z-index:9;"><span></span>Home</a></li>
<li><a href="#" style="z-index:8;">Books</a></li>
<li><a href="#" style="z-index:7;">Sale Books</a></li>
</ul>
</div>
<div id="newad">
<fieldset>
<legend><strong>Sale Books & Stationary</strong></legend>
<form >
<table width="499" >
<tr>
<td width="96">Select Class:</td>
<td width="139"><select required="required" x-moz-errormessage="Select the Class" name="class" id="select" onchange="showUser(this.value)">
<option selected="selected">Select class:</option>
胡说八道
是的,我知道先生,while 循环会给我无数的选择标签。