我正在为我们的网站优化一个表单,让用户使用下拉菜单完成它。我已经想出了如何根据 PHP 查询填充单个下拉菜单,但是我需要根据该选择填充另一个下拉菜单。我正在尝试将 onchange 属性用于选择标记。我知道我在 javascript 中的查询还不是动态的,但我只是想让它首先显示下一个下拉列表,但事实并非如此。当我从第一个下拉菜单中选择某些内容时,什么也没有发生。感谢您提前提供任何帮助。
$query2 = "select distinct Provider_Name from CE_ACTIVITY_LIST_T where IS_ACTIVE = 'YES'";
$result2 = mysql_query($query2, $link) or die(mysql_error());
//$row2 = mysql_fetch_array($result2) or die(mysql_error());
echo "<table border='0'><tr><th>";
echo "Course Provider:</th><td><select name='providerName' id='provider'onchange='getResult()'>";
echo "<option SELECTED>Pick Provider</option>";
$i=0;
while($row2 = mysql_fetch_array($result2))
{
echo "<option value=\"" . $row2['Provider_Name'] . "\">" . $row2['Provider_Name'] . "</option>";
$i++;
}
echo "</select></td></tr><tr></tr>";
<script type="text/javascript">
function getResult(field)
{
var field=field;
var isEqualTo=document.getElementById('provider');
document.getElementById('selectCourse').innerHTML = '<?php
include ('connectionOpen.php');
$queryCourse="select Course_Title from CE_ACTIVITY_LIST_T where Provider_Name = 'Test 1' and isActive = 'YES'";
echo "<tr><th>";
echo "Course Title:</th><td><select name='courseTitle'>";
echo "<option SELECTED>Which course?</option>";
$i=0;
while($row2 = mysql_fetch_array($result2))
{
echo "<option value=\"" . $row2['Course_Title'] . "\">" . $row2['Course_Title'] . "</option>";
$i++;
}
echo "</select>";
echo "</td></tr></table>";
?>';
}
</script>