我有两个select
个框,第二个框取决于第一个框中的选择。我希望第一个框(course
)更改时,第二个选择框(null
)的值为subject
。任何帮助实现这一点将不胜感激。
这就是我的尝试:
使用Javascript:
function autoSubmit() {
var formObject = document.forms['theForm'];
formObject.submit();
}
PHP:
<form name="theForm" method="get">
<select name="subject" onChange="autoSubmit();">
<option value="null">Select a Subject...</option>
<php
$sql = "SELECT DISTINCT subj_name, subj_id FROM table1 ORDER BY subj_name
$result = mysql_query($sql) or die ("couldn't execute query");
while($row = mysql_fetch_array($result))
{
echo ("<option value=\"$row[subj_id]\" " . ($subject == $row["subj_id"] ? "
selected" : "") . ">$row[subj_name]</option>");
}
?>
</select>
<select name="course" onChange="autoSubmit();">
<option value="null">All Courses</option>
<php
if($subject != null && is_numeric($subject))
{
$sql = "SELECT DISTINCT subj_id, course_id, course_name FROM table1
WHERE subj_id = $subject ORDER BY course_name
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo ("<option value=\"$row[course_id]\" " . ($course == $row["course_id"] ?
" selected" : "") . ">$row[course_number] - $row[course_name]</option>");
}
}
?>
</select>
</form>
答案 0 :(得分:2)
您可以在autoSubmit()
:
this.form.course.value='null';
或
this.form.course.selectedIndex=0;
这样,获取的值将为?subject=[the_subject]&course=null
(然后$course == $row["course_id"]
将为false)。