Options set in dynamic multiple select field with ajax are not preserved I am working on a dynamic set of three multiple select list which will function as one field which can be placed inside a form.  The options in the second and third select lists will be set based upon the selection in the first and second selects.  

Here is how I create the widget:

function multiselect_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
    $options_first = multiselect_first_dropdown_options();
    $value_dropdown_first = isset($form_state['values']['dropdown_first']) ? $form_state['values']['dropdown_first'] : key($options_first);

    $form['dropdown_first'] = array(
        '#type' =&gt; 'select',
        '#multiple' =&gt; TRUE,
        '#title' =&gt; 'First Dropdown',
        '#options' =&gt; $options_first,
        '#default_value' =&gt; $value_dropdown_first,
        '#ajax' =&gt; array(
            'event' =&gt; 'change',
            'callback' =&gt; 'multiselect_school_ajax_callback',
            'wrapper' =&gt; 'dropdown_second_replace',
        ),
    );
    $form['dropdown_second'] = array(
        '#type' =&gt; 'select',
        '#multiple' =&gt; TRUE,
        '#title' =&gt; 'Second Dropdown',
        '#prefix' =&gt; '&lt;div id="dropdown_second_replace"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
        '#options' =&gt; multiselect_second_dropdown_options($value_dropdown_first),
        '#default_value' =&gt; isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',

        '#ajax' =&gt; array(
            'event' =&gt; 'change',
            'callback' =&gt; 'multiselect_class_ajax_callback',
            'wrapper' =&gt; 'dropdown_assignment_replace',
        ),
      );
      $form['dropdown_assignment'] = array(
        '#type' =&gt; 'select',
        '#multiple' =&gt; TRUE,
        '#title' =&gt; 'Second Dropdown',
        '#prefix' =&gt; '&lt;div id="dropdown_assignment_replace"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
        '#options' =&gt; multiselect_second_dropdown_options($value_dropdown_first),
        '#default_value' =&gt; isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',
      );

  return $form;
}


And here is an example of one of my ajax callbacks:

function multiselect_school_ajax_callback($form, $form_state) {
      global $classes;
      $index = array_shift(array_values($form_state['values']['dropdown_first']));
      $selected_school = $form['dropdown_first']['#options'][$index];
      $class_array = multiselct_get_subgroups($selected_school, 'organization_group');
      $form['dropdown_second']['#options'] = $class_array;
      $classes = $class_array;
      return $form['dropdown_second'];
    }


When I set the options of the dropdown_second in my ajax callback, it causes the widget to be re-rendered with the correct contents but when I examine the value stored in $form['dropdown_second']['#options'] from any other hook the values I set are not preserved.  If I set $form['dropdown_second']['#options'] from hook_form_alter() the values are preserved but hook_form_alter is not called after my ajax call.  Is there some way to make these changes stick around from my ajax callback or force a hook_form_alter?
You can refer the following example for creating Dependent select list 

function multiselect_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
    $options_first = multiselect_first_dropdown_options();
    $value_dropdown_first = isset($form_state['values']['dropdown_first']) ? $form_state['values']['dropdown_first'] : key($options_first);

    $form['dropdown_first'] = array(
        '#type' =&gt; 'select',
        '#multiple' =&gt; TRUE,
        '#title' =&gt; 'First Dropdown',
        '#options' =&gt; $options_first,
        '#default_value' =&gt; $value_dropdown_first,
        '#ajax' =&gt; array(
            'event' =&gt; 'change',
            'callback' =&gt; 'multiselect_school_ajax_callback',
            'wrapper' =&gt; 'dropdown_second_replace',
        ),
    );
    $form['wrapper'] = array(
        '#prefix'  =&gt; '&lt;div id="dropdown_second_replace"&gt;',
        '#suffix'  =&gt; '&lt;/div&gt;',
    );
    if(!empty($form_state['values']['dropdown_first'])){
        // Code here or call function for  fetching value second and third dropdown
    }
    $form ['wrapper']['dropdown_second'] = array(
        '#type' =&gt; 'select',
        '#multiple' =&gt; TRUE,
        '#title' =&gt; 'Second Dropdown',
        '#prefix' =&gt; '&lt;div id="dropdown_second_replace"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
        '#options' =&gt; multiselect_second_dropdown_options($value_dropdown_first),
        '#default_value' =&gt; isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',

        '#ajax' =&gt; array(
            'event' =&gt; 'change',
            'callback' =&gt; 'multiselect_class_ajax_callback',
            'wrapper' =&gt; 'dropdown_assignment_replace',
        ),
    );
    $form['wrapper']['dropdown_assignment'] = array(
        '#type' =&gt; 'select',
        '#multiple' =&gt; TRUE,
        '#title' =&gt; 'Second Dropdown',
        '#prefix' =&gt; '&lt;div id="dropdown_assignment_replace"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
        '#options' =&gt; multiselect_second_dropdown_options($value_dropdown_first),
        '#default_value' =&gt; isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',
    );
    return $form;
}


The basic idea about above example is that use wrapper as a div which will have your second and third dropdown so on change of first drop down form state will be set so it will go into if condition than that will give you the value for the secoond and third drop down