How to dynamically populate select options?
As said before you could make use of Form APIs #states to display one element only after a certain input to another form element has been made. In your case you'd maybe go with two additional select lists, both initially hidden. Check form_examples_states_form() for more information.

$form['main'] = array(
  '#type' =&gt; 'select',
  // ...
);
$form['sub_a'] = array(
  '#type' =&gt; 'select',
  // ...
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="main"]' =&gt; array('value' =&gt; 'foo'),
    ),
  ),
);
$form['sub_b'] = array(
  '#type' =&gt; 'select',
  // ...
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="main"]' =&gt; array('value' =&gt; 'bar'),
    ),
  ),
);