2009-06-11 118 views
2

所以我使用了一个带有国家列表的HTML选择框和一个按钮来打开一个小窗口,其中包含HTML选择框中所选项目的更多详细信息。我的HTML下拉菜单在IE6中不起作用

以下是我正在做这个(我提前道歉这里任何noobishness,我还是很新的JavaScript):

//in header 
<script type="text/javascript"> 
function popUp() 
{ 
    countryName = document.getElementById("countrylist").value; 
    document.write(countryName); 
    dest = "countries/" + countryName + ".html"; 
    window.open(dest, 0, "toolbar=0, scrollbars=0, statusbar=0, menubar=0,resizable=0,width=400,height=400,left=440,top=312"); 
} 
</script> 

<form id="countryform"> 
<select id="countrylist"> 
     <!--List of countries removed for brevity--> 
</select> 
<input type="button" name="countryBtn" value="Submit Query" onClick="popUp();"> 
</form> 

能正常工作在Firefox,但不是在IE6。任何帮助,将不胜感激!

UPDATE:所以,我想下面的前两种方法,替代弹出功能并没有在任何浏览器中运行,并更换的document.getElementById线没有任何改变,仍然在Firefox正常工作,不在IE中。

回答

0

以下是我固定它:

function popUp() 
{ 
    var c = document.getElementById("countrylist"); 
    var countryName = c.options[c.selectedIndex].text; 
    var dest = "countries/" + countryName + ".html"; 
    window.open(dest, 0, "toolbar=0, scrollbars=0, statusbar=0, menubar=0,resizable=0,width=400,height=400,left=440,top=312"); 
} 

这个工作在两个IE6和FF3。

感谢您的帮助!

6
document.getElementById("countrylist").value; 

需要是:

document.getElementById("countrylist")[document.getElementById("countrylist").selectedIndex].value; 
+0

良好的通话! 。 – 2009-06-11 18:19:19

0

您遇到的问题是与国名的获得。我会改变您的弹出功能是:

function popUp() { 

    var e = document.getElementById("countrylist"); 

    var countryName = e.options[e.selectedIndex].value; 

    dest = "countries/" + countryName + ".html"; 
    window.open(dest, 0, "toolbar=0, scrollbars=0, statusbar=0, menubar=0,resizable=0,width=400,height=400,left=440,top=312"); 

}