Drop down disabling/enabling

Discussion in 'JavaScript' started by Cobnut, May 27, 2010.

  1. #1
    I hope someone can help with what I suspect is a simple task. I have three drop downs in a form, let's call them A, B and C. Each dropdown has an 'Any' option, value 0 and an unspecified number of other options, values 1->N.

    If A OR B are !=0, then C should be disabled. If A & B return to 0 then C should be re-enabled. If C is !=0, then A AND B should both be disabled. If C returns to 0 then A AND B should be enabled again.

    If this makes sense then I'd be very grateful for any code to provide this functionality. I've got part of it working but not all.

    Any comments appreciated.
     
    Cobnut, May 27, 2010 IP
  2. rkstech

    rkstech Active Member

    Messages:
    195
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #2
    you might want to use the toggle field, same code for your requirement
     
    rkstech, May 28, 2010 IP
  3. Cobnut

    Cobnut Peon

    Messages:
    184
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not sure what you mean rkstech, by 'toggle' are you referring to the behaviour of radio buttons in a group? These are three drop-downs containing mulitple values which cannot (effectively) be replaced by check boxes or radio buttons.
     
    Cobnut, May 28, 2010 IP
  4. wab

    wab Member

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    I think you can use some JQuery, with something like:
    
    $(document).ready(function() {
         $('#A').change(function() { 
             if($(this).val()!=0 || $('#B').val()!=0){
                  $('#C').attr("disabled") == true; 
             }
              if($(this).val()==0 && $('#B').val()==0){
                  $('#C').attr("disabled") == false; 
             }
         });
    });
    
    Code (markup):
    Just adapt it for your different cases.
     
    wab, May 28, 2010 IP