0

I have the following code where 2 drop downs are available on the UI. When I select value "1" of drop down 1, the drop down 2 should be disabled. When I select value "1", the dropdown 2 is disabled. But I am not able to re-enable the drop down 2 when the user select value "2" from drop down 1. I am not sure since I am calling the performValidation() method for onClick event of both the options in drop down 1.

Code:

<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>
1
  • Not sure, your code works for me as is in Firefox 4.0 Commented Mar 24, 2011 at 20:18

2 Answers 2

2

You need to wire up a function to the onchange event on the select something like

document.getElementById("criteriaOne").onchange = function() 
         { // do some work to check the selectedIndex and determine whether to re-                enable the other drop down}
Sign up to request clarification or add additional context in comments.

Comments

0

You don't necessarily need

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

1 Comment

presence/absence of that line doesn't solve my problem however !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.