我有每个主要类别的一些主要类别和子类别..我有一个包含主要类别的下拉列表,当我选择一个主要类别时,子类别下拉列表显示该主要类别的子类别..我为此使用以下代码,但这表明子类别框包含带有页眉和页脚的整个页面...
<select name="main_category" id="main_category" onchange="showSubCategory(this.value)">
<option>--Select--</option>
</select>
<script type="text/javascript">
function showSubCategory(str)
{
if (str.length==0)
{
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)
{
alert(xmlhttp.responseText);
document.getElementById("subcategory").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","index.php?main_page=getsubcategory&cid="+str,true);
xmlhttp.send();
}
</script>
在 tpl_subcategory_default.php 包含
<?php
$cid=$_GET['cid'];
$sql="select cd.categories_name, cd.categories_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.parent_id = '" . (int) $_GET['cid'] . "'
and c.categories_id = cd.categories_id
and c.categories_status= 1";
$r=mysql_query($sql);
while($row=mysql_fetch_array($r))
{
echo "<option value=$row[categories_id]>$row[categories_name]</option>";
}
?>