基本上,我尝试完成的是当有人点击第一个html下拉列表id="FirstDD"
时,根据所选的option
,第二个下拉列表id="SecDD"
会填充字段与FirstDD
下拉选项相关联。触发这一切是ajax来执行初始调用和php来处理subcategories.php
。
目前,正在发生的事情是:我选择了第一个下拉列表,但SecDD
JS / AJAX:
<script type="text/javascript">
$(document).ready(function(){
$("#FirstDD").change(function(){
$('#SecDD').load('inc/subcategories.php?scatID='+this.value);
});
});
</script>
HTML
<select style="width:300px;" id="FirstDD" name="userListingCategory">
<!--onchange="$('#SecDD').load('inc/subcategories.php?scatID='+this.value);"-->
<option disabled="disabled">Category...</option>
<?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $categoryID . ">" .$row['catName']."</option>";}
unset($sth2);
?>
</select>
<select style="width:340px;" id="SecDD" name="userListingSCategory" style="display:none">
<?php require_once('inc/subcategories.php'); ?>
</div>
</select>
Subcategories.php
<?php require_once('db/dbc.php');
#GET SELECT sub-category names
$pdo3 = new PDO($h1, $u, $p);
$pdo3->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth3 = $pdo3->prepare("
SELECT scatID, scatName
FROM Category C, SubCategory SC
WHERE C.catID = SC.catID
;");
$sth3->execute(array());
?>
<option disabled="disabled">Sub-Category...</option>
<?php
#Get subcats
while($row = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
unset($sth3);
?>
答案 0 :(得分:0)
诊断问题:
如果每次都能正常工作,那么某些事情就不会触发,但代码似乎从这里开始。在那之后,我会尝试在你的行之间放置echo语句,看看它停在哪里。