Dependent multiple selection drop down in drupal form - illegal choice error 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.

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.

Please help me how to use 2 multi select dependent drop down in drupal.

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.

function policy_node_form(){
$form['field_department'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; 'Department',
    '#multiple' =&gt; TRUE,
    '#options' =&gt; array(
        '' =&gt; t('-Select-'),
        '1444' =&gt; t('department1'),
        '1445' =&gt; t('department2'),
        '1446' =&gt; t('department3'),
        '1447' =&gt; t('department4'),
        '1448' =&gt; t('department5'),
        '1449' =&gt; t('department6')                      
        )       
);
$form['field_policy_categories'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; 'Categories',
     '#multiple' =&gt; TRUE,
    '#options' =&gt; array()
);

}
function page_form_alter(&amp;$form, &amp;$form_state, $form_id) {

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'];
}
To try take your second $form['field_policy_categories']['und']['#options'] to individual function instead of inside hook_form_alter().

function page_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  if ($form_id == 'policy_node_form') {
    $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;

  $form['field_policy_categories']['und']['#options'] = categories_options($form_state);

  $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 categories_options($form_state) {
  // option go to here
}


.