Form with AJAX callback to query database and display info in block['content']
You should do all the logic in the form function. However with your particular issue, I would approach it slightly differently. I would simply return the table HTML from displayMortgages() back to the form and display the table as part of the form. But just simply as a #type=&gt; 'markup'. That way, your sort form and the results are one, and you don't need to worry about firing off another ajax command somewhere else.

So your form code would basically be:

function mortgage_multi_view_sort_form($form, &amp;$form_state) {
  $form = array();

  // Default sort direction
  $sort_dir = 'DESC';

  $sortOptions = array(
    'DESC' =&gt; t('Mortgage Duration: Shortest to Longest'),
    'ASC' =&gt; t('Mortgage Duration: Longest to Shortest'),
  );

  $form['mortgage_sort'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Sort By'),
    '#options' =&gt; $sortOptions,
    '#default_value' =&gt; 'DESC',
    '#required' =&gt; TRUE,
    '#ajax' =&gt; array(
      'event' =&gt; 'change',
      'callback' =&gt; 'ajax_select_callback',
      'wrapper' =&gt; 'replace_model_div',
      'method' =&gt; 'replace',
      //'effect' =&gt; 'fade',
    ),
  );

  // Check if a selection on the form has been made, if so then update the direction
  if (isset($form_state['values']['mortgage_sort'])) {
    $sort_dir = $form_state['values']['mortgage_sort'];
  }

  $result = db_query('SELECT * FROM {mortgage_database} ORDERBY duration '.$sort_dir);

  $form['result'] = array(
    '#markup' =&gt; (count($result)) ? displayMortgages($result) : '',
    '#prefix' =&gt; '&lt;div id="replace_model_div"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );

  return $form;
}


And you just need to return the part that's being replaced in your ajax callback:

function ajax_select_callback($form, &amp;$form_state) {
  // Just a return of result is sufficient since it's being replaced
  return $form['result'];
}