2011-03-24 149 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

相關問題