Enable DropDown using Ajax Call As given in the code below, I tried enabling select list $form['answer']['answer1'] through AJAX callback, textbox is getting populated with value, where as the dropdownlist is not getting enabled. Any help?

function mymodule_search_block_form($form, &amp;$form_state) {
  $options = array();
  $options['key1'] = t('value1');
  $options['key2'] = t('value2');
  $options['key3'] = t('value3');
  $options['key4'] = t('value4');

  $form['profiles'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; 'Profiles',
    '#options' =&gt; $options,
    '#ajax' =&gt; array(
        'callback' =&gt; 'ajax_select_callback',
        'wrapper' =&gt; 'profile-wrapper',
        'event' =&gt; 'change',
    ),
  );

  $form['answer']['profile_name'] = array(
    '#prefix' =&gt; '&lt;div id="profile-wrapper"&gt;',
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Profile Name1',
  );
  $form['answer']['profile_name2'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Profile Name2',
  );
  $form['answer']['answer1'] = array(
    '#type' =&gt; 'select',
    '#disabled' =&gt; 1,
    '#title' =&gt; 'Profiles',
    '#options' =&gt; $options,
    '#suffix' =&gt; '&lt;/div&gt;&lt;/br&gt;',
  );
  return $form;
}

function ajax_select_callback($form, $form_state) {
  $form['answer']['profile_name']['#value'] = 'Profile 1';
  $form['answer']['profile_name2']['#value'] = 'Profile 2';
  $form['answer']['answer1']['#disabled'] = 0;
  return $form['answer'];
}
Interesting question. The way I see it there are actually two parts to this. This first is, of course, your actual question and that can be easily solved:

// Your code in ajax_select_callback().
unset($form['answer']['answer1']['#attributes']['disabled']);
$form['answer']['answer1']['#disabled'] = 0;
// More of your code in ajax_select_callback().


When you set the #disabled property of a form element to TRUE, what Drupal does is simply add the disabled attribute to the element and allows the renderer (i.e. drupal_render()) to do its job. In your AJAX callback, the $form array passed is that of the rendered form. This means that the your dropdown element already has the disabled attribute on it. Therefore, when it is rendered again, it still shows up disabled. So, to prevent this, we simply remove the attribute.

However, you'd notice that when you submit your form after this, the value of the disabled dropdown (in $form_state['values']) may not be the value you chose after "enabling" it. This is because your form is not being re-built on the server which means that Drupal still thinks your dropdown is disabled and will refuse to process your input, simply ignoring it and using the default. If you are able to reproduce this, comment on this answer and I'll update this post with a solution for that problem.