下拉列表中的onclick事件未被调用

时间:2013-04-19 05:58:06

标签: javascript dynamic drop-down-menu

我将以下Combobox“选择页面”动态添加到jsp页面,在更改时会填充另一个名为“Objects”的组合框。选择页面下拉列表正在正确加载内容,但不会触发事件。即populateObjects。我在populateObjects()函数中保持警告,这表明它甚至没有调用此警报。请帮忙。

//Select Page
       var cell4 = row.insertCell(3);
       var element4 = document.createElement("select");
       element4.setAttribute('id', 'selPageRow' + rowCount);
       element4.setAttribute('name', 'selPageRow' + rowCount);
       element4.setAttribute('onClick', 'javascript:populateObjects(this.options[this.selectedIndex].innerHTML,'+rowCount+');');
       var PageArray = getPages();
       var option = document.createElement("option");
       option.text = "Select..."; 
       option.value = "select"; 
       element4.options.add(option);
       for(var i=0;i<PageArray.length;i++)
           {
               var option = document.createElement("option");
               option.text = PageArray[i].attributes[0].nodeValue; 
               option.value = PageArray[i].attributes[0].nodeValue;  
               element4.options.add(option);
           }
       cell4.appendChild(element4); 

// Code for populating Object dropdown

    function populateObjects(selectedValue,rowCount)
    {
        alert(selectedValue);
        var SelBox = document.getElementById('selObjRow' + rowCount);
        removeAllOptions(SelBox);
        var ObjArry = getObjects(selectedValue);

        var option = document.createElement("option");
        option.text = "Select..."; 
        option.value = "select"; 
        SelBox.options.add(option);
        if(ObjArry.length>0)
        {
            for(var i=0;i<ObjArry.length;i++)
               {
                   var option = document.createElement("option");
                   option.text = ObjArry[i].attributes[0].nodeValue; 
                   option.value = ObjArry[i].attributes[0].nodeValue;  
                   SelBox.options.add(option);
               }
        }
        else
        {
            var option = document.createElement("option");
            option.text = "None"; 
            option.value = "none"; 
            SelBox.options.add(option);
        }
        cell5.appendChild(SelBox);
    }

1 个答案:

答案 0 :(得分:0)

onClick事件更改为onChange事件

   element4.setAttribute('onChange', 'javascript:populateObjects(this.options[this.selectedIndex].innerHTML,'+rowCount+');');