Update default value of form element with AJAX I have an email field on node add form , I want to check if this email exist fill the city field in the same node form , then my code is : 

function custom_code_form_car_node_form_alter(&amp;$form, &amp;$form_state, $form_id){
  $form["field_user_email"]['und'][0]['email']['#ajax'] = array(
      'callback' =&gt; 'user_ajax_check',
      'wrapper' =&gt; 'field-user-city-add-more-wrapper',
      'effect' =&gt; 'fade',
  );
}


function user_ajax_check($form,$form_state){
    // load the user then
    $form["field_user_city"]['und'][0]['value']["#default_value"] ="foo";
    return $form["field_user_city"];
}
The value must be set in the hook_form_alter, not in the callback of ajax :

function custom_code_form_car_node_form_alter(&amp;$form, &amp;$form_state, $form_id){
  $form["field_user_email"]['und'][0]['email']['#ajax'] = array(
      'callback' =&gt; 'user_ajax_check',
      'wrapper' =&gt; 'field-user-city-add-more-wrapper',
      'effect' =&gt; 'fade',
  );

  if(!empty($form_state['values']['field_user_email']){
       $form["field_user_city"]['und'][0]['value']["#default_value"] = "foo";
  }
}


function user_ajax_check($form,$form_state){
    // load the user then       
    return $form["field_user_city"];
}