Difficulties with the #ajax form item attribute My form item is the following one: 

$form['foo'] = array( 
  '#title' =&gt; t('Foo'),
  '#type' =&gt; 'radios',
  '#options' =&gt; $options,
  '#description' =&gt; t('Lorem ipsum.'),                                                     
  '#required' =&gt; true,
  '#ajax' =&gt; array(
    'callback' =&gt; 'foo_get_js', 
    'wrapper' =&gt; 'foo-wrapper',
    'event' =&gt; 'click',
    'method' =&gt; 'replace',          
  ),
);


My AJAX function is the following one:

function foo_get_js($form, $form_state) {
  return mktime().'&lt;xmp&gt;'.print_r($form_state['values'], true).'&lt;/xmp&gt;';
}


My wrapper will get updated the first time the ajax call is made, but after that it will stay the same: the time and $form_state don't get updated. If I use the 'append' method instead of the 'replace' method then everything works as intended.

Is it the supposed behavior?
Since 'foo-wrapper' is replaced at the first call, it doesn't exist in the second call, and therefore, the callback doesn't know where to put the return value.

A simple solution would be to include a wrapper in the return value, with the same id as 'foo-wrapper'.

function foo_get_js($form, $form_state) {
  return '&lt;div id="foo-wrapper"&gt;' . mktime() . '&lt;xmp&gt;' . print_r($form_state['values'], true) . '&lt;/xmp&gt;&lt;/div&gt;';
}


Please note that this is untested.