2011-03-24 153 views
0

我有以下代码,其中2个下拉列表可用于用户界面。当我选择下拉1的值“1”时,下拉2应该被禁用。当我选择值“1”时,下拉2被禁用。但是,当用户从下拉列表中选择值“2”时,我无法重新启用下拉菜单2.我不确定,因为我正在调用performValidation()方法,因为onClick事件的下拉列表中的两个选项均为1.启用/禁用下拉列表 - Javascript

代码:

<html> 
<head></head> 
<script = "text/javascript"> 
    function performValidation() 
    { 
      if (document.mainForm.criteriaOne.value == "1") 
      { 
       document.mainForm.criteriaTwo.options.length = 0; 
       document.mainForm.criteriaTwo.disabled = true; 
      } 
      else 
       document.mainForm.criteriaTwo.disabled = false; 
    } 
</script> 
<body> 
     <form name="mainForm" action= "" method ="get"> 
       Criteria One:<select id = "criteriaOne"> 
      <option value = "1" onClick ="performValidation()"> Select One - One</option> 
      <option value = "2" onClick ="performValidation()"> Select one - Two</option> 
       </select> 
       Criteria Two:<select id = "criteriaTwo"> 
      <option value = "1" onClick ="performValidation()"> Select Two - One</option> 
       </select> 
     </form> 
</body> 
</html> 
+0

不确定,你的代码适用于我,就像在Firefox 4.0中一样 – Duniyadnd 2011-03-24 20:18:10

回答

2

你需要一个功能电线到onchange事件上的选择像

document.getElementById("criteriaOne").onchange = function() 
     { // do some work to check the selectedIndex and determine whether to re-    enable the other drop down} 
0

你不一定需要

document.mainForm.criteriaTwo.options.length = 0; 
+0

存在/缺少该行并不能解决我的问题! – 2011-03-24 20:14:58

相关问题