如何使用我的.selecteindex;value从选择框作为我的索引在我的PHP请求


How do I use my ".selectedIndex;" value from select box as my index in my PHP request?

我有一个选择框,它使用"onchange"来根据用户的选择选择一个值。

//AddSelect start of function
    var TownSelect = function(options){
        var _dom_element = document.createElement("select");
            _dom_element.id = 'selectMenu';
        for ( var i = 0; i < options.length; i++ ) {
        var _option = document.createElement("option");
            _option.value = options[i];
            _option.innerHTML = options[i];
            _dom_element.appendChild(_option);
            _dom_element.onchange = function(){
            var checkValue = document.getElementById('selectMenu').selectedIndex;
                //alert(options [checkValue]);
            };
        }
        this.getDomElement = function() {
            return _dom_element;
        }
    }
    //AddSelect end of function

这里我有我的dojo ajax函数,使请求到我的PHP文件使用索引(ntown),我需要=我的选择菜单选定值的值(希望有意义):

     var _getWeatherInfo = function(ntown){
     dojo.xhrget({
         url: "PHP/weather.php?ntown=" + ntown,
         handleAs: "json",
         timeout: 5000,
         load: function(response) {
               _refreshWeatherList(response); 
         },
         error: function(error_msg, response) {
             _handleError(error_msg);
         }
     });
 }

我的最后一个问题引起了一些混乱,如果你需要更多的信息或更好的解释,请问我。谢谢你的帮助!

您必须在onchange函数中调用_getWeatherInfo作为函数 !

_dom_element.onchange = function(){
   var checkValue = document.getElementById('selectMenu').selectedIndex;
   _getWeatherInfo(checkValue);
 };