Javascript 如何根据以前下拉框的值更新下拉框

Javascript 如何根据以前下拉框的值更新下拉框,javascript,php,jquery,html,drop-down-menu,Javascript,Php,Jquery,Html,Drop Down Menu,我目前是javascript的初学者,很难传递下拉框的值。我只知道如果我将select内容包装到一个post表单中,并创建一个按钮来在单击时获取值,那么如何将值输入到php中,但由于这是javascript,因此没有提交按钮,我需要根据第一个下拉列表的值更新第二个下拉列表,并根据第一个和第二个下拉列表更新第三个下拉列表第二个价值观 我的桌子看起来像这样: 目前,我的代码只在下拉框中存储值。我想让它做的是,如果盖伊选择一月,选择第一周,一年应该只包含2015年,当他选择第二周,一年应该只包含20

我目前是javascript的初学者,很难传递下拉框的值。我只知道如果我将select内容包装到一个post表单中,并创建一个按钮来在单击时获取值,那么如何将值输入到php中,但由于这是javascript,因此没有提交按钮,我需要根据第一个下拉列表的值更新第二个下拉列表,并根据第一个和第二个下拉列表更新第三个下拉列表第二个价值观

我的桌子看起来像这样:

目前,我的代码只在下拉框中存储值。我想让它做的是,如果盖伊选择一月,选择第一周,一年应该只包含2015年,当他选择第二周,一年应该只包含2013年

<?php

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("my_db") or die (mysql_error());

$queryMonth = mysql_query("SELECT DISTINCT month FROM list WHERE username='guy'");
$queryWeek = mysql_query("SELECT DISTINCT week FROM list WHERE username='guy', month='Should be the value of the first select'");
$queryYear = mysql_query("SELECT DISTINCT year FROM list WHERE username='guy', month='Should be the value of the first select', week='Should be the value of the second select'");

?>      

<html>
<head>
<script src="js/javascript.js"></script>
<script>
function getMonth() {
document.getElementById("monthchoice").value = document.getElementById("month").value;
}

function getWeek() {
document.getElementById("weekchoice").value = document.getElementById("week").value;
}

function getYear() {
document.getElementById("yearchoice").value = document.getElementById("year").value;
}
</script>
</head>
<body>

<select id="month" onchange="getMonth()" >
<option value="" disabled selected>Select your option</option>
<?php  
while($getMonth = mysql_fetch_assoc($queryMonth))
{
echo 
'
<option value="'.$getMonth['month'].'">'.$getMonth['month'].'</option>
';
}
?>
</select>

<select id="week" onchange="getWeek()" >
<option value="" disabled selected>Select your option</option>
<?php  
while($getWeek = mysql_fetch_assoc($queryWeek))
{
echo 
'
<option value="'.$getWeek['week'].'">'.$getWeek['week'].'</option>
';
}
?>
</select>

<select id="year" onchange="getYear()" >
<option value="" disabled selected>Select your option</option>
<?php  
while($getYear = mysql_fetch_assoc($queryYear))
{
echo 
'
<option value="'.$getYear['year'].'">'.$getYear['year'].'</option>
';
}
?>
</select>
<br><br>
<input type="text" id="monthchoice"><br>
<input type="text" id="weekchoice"><br>
<input type="text" id="yearchoice"><br>

</body>
</html>

您应该研究ajax

当您的dropdownboxvalue的值更改时。您可以使用ajax从服务器请求新数据。如果需要,服务器应该返回json数据类型或xml。然后将从服务器接收的数据解析为javascript对象。然后使用javascript将旧的dropdownboxvalue值替换为从服务器收到的新的dropdownboxvalue,然后我建议您使用jquery,因为它对于初学者来说非常容易使用