Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript从下拉列表中获取值_Javascript_Drop Down Menu - Fatal编程技术网

javascript从下拉列表中获取值

javascript从下拉列表中获取值,javascript,drop-down-menu,Javascript,Drop Down Menu,我有一个php脚本,其中包含一个数组,该数组在几个月内循环并在下拉列表中显示它们。我想使用javascript从下拉列表中获取所选值 function month_list() { $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); echo '<sel

我有一个php脚本,其中包含一个数组,该数组在几个月内循环并在下拉列表中显示它们。我想使用javascript从下拉列表中获取所选值

function month_list()
{


 $months = Array("January", "February", "March", "April", "May", "June", "July", 
 "August", "September", "October", "November", "December");

 echo '<select name="month" id="month_list" OnChange="getvalue();">'; 

 foreach ($months as $months => $month)
 {
         echo'<option OnChange="getvalue();" value='.$month.'>'.$month.'</option>';

     }

 echo '</select>';

}
有什么建议吗


谢谢。

你忘了报月单了

 document.getElementById("month_list").value
另外,您不需要在单个选项上使用onchange(即所有小写字母)属性,只需要在select元素上使用

函数getvalue()
{
警报(document.getElementById('month_list')。值);
}
相反


此外,您还可以删除每个选项的onChange,选择即可:)

谢谢!哦,是的,我忘了我把那部分忘在:)
Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
 document.getElementById("month_list").value
function getvalue()
{
alert(document.getElementById('month_list').value); 
}

</script>