Select list ajax callback fire only once to update textfield I face an issue when fire ajax callback function in my coding. I have a select list and a text box. If there is any change in select list field, the text box will be updated by selected value. I added my code in form_alter function. But, it fired only one time. Below is my code.

 function field_collection_form_alter(&amp;$form, &amp;$form_state, $form_id) {
if($form_id == 'employee_performance_node_form') {

$form['field_my_weight_select'][LANGUAGE_NONE]['#ajax']= array(
      'callback' =&gt; 'custom_test_entity_callback',
      'wrapper' =&gt;'custom_test_entity_wrapper',
      'method' =&gt; 'replace',
      'effect' =&gt; 'fade',
      'event' =&gt; 'change',
    );

$form['field_text_for_test']['#prefix']='&lt;div id="custom_test_entity_wrapper"&gt;';  
$form['field_text_for_test']['#suffix']='&lt;/div&gt;';


if(isset($form_state['values']['field_my_weight_select'])){     
      $content_type = $form_state['values']['field_my_weight_select'][LANGUAGE_NONE][0]['value'];
      $form["field_text_for_test"][LANGUAGE_NONE][0]['value']['#value']=$content_type;
    }
    else{ $form["field_text_for_test"][LANGUAGE_NONE][0]['value']['#value']=1;}
}
}

function custom_test_entity_callback($form, $form_state){
  return $form['field_text_for_test'];
}


Could you tell me what is wrong in my code??

Thank you
Quickly tested your code and it works.

The only thing that looks a bit odd in your hook implementation, is the name of the function. It seems you are writing your custom code as if your module was named 'field_collection'. There is already a contrib module called that, and you may have already installed it. It would be better to place your function into your custom module's "namespace". Event better would be to also use the hook_form_FORM_ID_alter hook, since it's more efficient.

In any case, with those two small rewrites, the code ran as expected and I was able to get multiple ajax updates of the text_for_test field.

/**
 * Implements hook_form_FORM_ID_alter().
 */
function YOUR_CUSTOM_MODULE_form_employee_performance_node_form_alter (&amp;$form, &amp;$form_state) {
  $form['field_my_weight_select'][LANGUAGE_NONE]['#ajax'] = array(
    'callback' =&gt; 'custom_test_entity_callback',
    'wrapper' =&gt; 'custom_test_entity_wrapper',
    'method' =&gt; 'replace',
    'effect' =&gt; 'fade',
    'event' =&gt; 'change',
  );

  $form['field_text_for_test']['#prefix'] = '&lt;div id="custom_test_entity_wrapper"&gt;';
  $form['field_text_for_test']['#suffix'] = '&lt;/div&gt;';

  if (isset($form_state['values']['field_my_weight_select'])) {
    $content_type = $form_state['values']['field_my_weight_select'][LANGUAGE_NONE][0]['value'];
    $form["field_text_for_test"][LANGUAGE_NONE][0]['value']['#value'] = $content_type;
  }
  else {
    $form["field_text_for_test"][LANGUAGE_NONE][0]['value']['#value'] = 1;
  }
}

/**
 * Ajax callback for updating field_text_for_test.
 */
function custom_test_entity_callback($form, $form_state) {
  $form['field_text_for_test']['#prefix'] = '&lt;div id="custom_test_entity_wrapper"&gt;';
  $form['field_text_for_test']['#suffix'] = '&lt;/div&gt;';
  return $form['field_text_for_test'];
}


Update: If you want to make sure, your form alter hook is called last (in relation to other modules):

/**
 * Implements hook_module_implements_alter().
 */
function CUSTOM_MODULE_module_implements_alter(&amp;$implementations, $hook) {
  if ($hook != 'form_employee_performance_node_form_alter') {
    return;
  }
  $module = 'CUSTOM_MODULE';
  $group = array($module =&gt; $implementations[$module]);
  unset($implementations[$module]);

  $implementations = $group + $implementations; //You want your implementation to run last.
}


Good luck!