ajax callback add more on a select field
After an AJAX submit by a select or some similar not submit element the Form API rebuilds de form if no validate errors are found. See drupal_process_form() where this is stated in the inline comments:    


// However, for forms that have not been fully executed (e.g., Ajax
// submissions triggered by non-buttons), there is no submit handler to set
// $form_state['rebuild']. It would not make sense to redisplay the
// identical form without an error for the user to correct, so we also
// rebuild error-free non-executed forms, regardless of
// $form_state['rebuild'].



Your code is not working because you update your number of elements in the callback function in this line:

$form_state['num_names'] = $form_state['values']['myfield'];


The callback function is executed after all form processing so your modifications are done too late. In fact, callback function should only return the response, no modifications on the form should be done here.

Try something like this:

$form['myfield'] = array(
    '#type' =&gt; 'select',
    '#options' =&gt; $optionsServer,
    '#ajax' =&gt; array(
        'callback' =&gt; 'ajax_select_change',
        'wrapper' =&gt; 'names-fieldset-wrapper',
        'method' =&gt; 'replace',
        'effect' =&gt; 'fade',
    ),
);

$form['#tree'] = TRUE;
if (empty($form_state['num_names'])) {
   $form_state['num_names'] = 1;
}
else {
  // If there's is value in myfield update number of available names elems.
  $form_state['num_names'] = $form_state['values']['myfield'];
}


$form['myfieldset'] = array(
        '#type' =&gt; 'fieldset',
        '#title' =&gt; t('myfieldset'),
        '#prefix' =&gt; '&lt;div id="names-fieldset-wrapper"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
    );
for ($i = 0; $i &lt; $form_state['num_names']; $i++) {
   $form['myfieldset']['field'.$i] = array(
       '#type' =&gt; 'textfield',
       '#title' =&gt; t('field'),
       '#size' =&gt; 60,
       '#required' =&gt; TRUE,
   );
}

function ajax_select_change($form, &amp;$form_state){
    return $form['myfieldset'];
}