title: dependent muti select drop down in drupal 7
body: <p>I'm new to Drupal , in my project I have 2  multiple select drop down box. I don't know how to do dependent multi select drop down action in drupal form alter function using ajax.</p>
  
  <p>Single selection dependent drop down selection is working. But when i tried the same in case of 2 multi select dependent drop down i couldn't find any solution . On multi select error "An illegal choice has been detected. Please contact the site administrator." is shown.</p>
  
  <p>Please help me how to use 2 multi select dependent drop down in drupal.</p>
  
  <p>Here is my code :  here "field_department" is the 1st multi select drop down. "field_policy_categories" is the 2nd muti select drop down. i want 2nd drop down values corresponding to 1st field's multi selected options.</p>
  
  <pre><code>if ($form_id == 'policy_node_form') {
      $category = array();
      $category[''] = '- None -'; 
  
      $form['field_department']['und']['#ajax'] = array(         
          'wrapper' =&gt; 'policy_category_list',
          'callback' =&gt; 'ajax_policy_category_callback',
          'method' =&gt; 'replace',
      );
  
      $form['field_policy_categories']['#validated'] = TRUE;
      $form['field_file_upload']['#validated'] = TRUE;
  
      if (isset($form_state['values']['field_department'])) {            
  
          $array_departments = array($form_state['values']['field_department']['und']['0']['tid']);
  
          $query = db_select('field_data_field_department', 'f');
          $query-&gt;join('taxonomy_term_data', 't', 'f.entity_id = t.tid');
          $query-&gt;join('taxonomy_term_hierarchy', 'h', 't.tid = h.tid');
  
          $query-&gt;condition('f.entity_type', 'taxonomy_term', '=');
          $query-&gt;condition('f.bundle', 'policy_categories', '=');            
          $query-&gt;condition('f.field_department_tid', $array_departments, 'IN');
          $query-&gt;condition('h.parent', 0, '=');
          $query-&gt;fields('f');
          $query-&gt;fields('t');
          $query-&gt;fields('h');
          $result = $query-&gt;execute();
  
          $policy_vid = taxonomy_vocabulary_machine_name_load('policy_categories')-&gt;vid;
  
          $category[''] = '- None -';
  
          foreach ($result as $record) {
              $parent_arr = taxonomy_get_parents_all($record-&gt;tid);
              $parent_level = sizeof($parent_arr);
              $parent_level--;
              $parent_tid = $parent_arr[$parent_level]-&gt;tid;
              $parent_name = $parent_arr[$parent_level]-&gt;name;
              $category[$parent_tid] = $parent_name;
  
              $policy_children_arr = taxonomy_get_tree($policy_vid, $parent_tid);
              foreach ($policy_children_arr as $key =&gt; $policy_children) {
                  $depth = '';
                  for ($i = $policy_children-&gt;depth; $i &gt;= 0; $i--)
                      $depth .= '--';
                  $category[$policy_children-&gt;tid] = $depth . $policy_children-&gt;name;
              }
          }
  
          $form['field_policy_categories']['und']['#options'] = $category;
      } else {
  
          $form['field_policy_categories']['und']['#options'] = $category;
      }
  
      $form['field_policy_categories']['#prefix'] = '&lt;div id="policy_category_list"&gt;';
      $form['field_policy_categories']['#suffix'] = '&lt;/div&gt;';
  
      $form['#validate'][] = 'form_validate_policy_add';
  }
  
  function ajax_policy_category_callback($form, &amp;$form_state) {
  
      return $form['field_policy_categories'];
  }
  </code></pre>