title: Drupal Dynamic Select on a Form
body: <p>I'm sure this is an easy one for jQuery experts, but I'm a backend guy, and can't find the best way to do this.  I have two arrays in Drupal, one is a list of names of views, and the other is an array that contains a list of displays for each view.  Here's the code to populate the two arrays:</p>
  
  <pre><code> //load list of views in to array for select lists
  $views = views_get_all_views();
  $viewnames = array();
  $viewdisplays = array();
  foreach ($views as $view) {
    $viewnames[$view-&gt;name] = $view-&gt;name; 
    foreach ($view-&gt;display as $k) {
      $id = $k-&gt;id;
      $title = $k-&gt;display_title;
      $viewdisplays[$view-&gt;name]['id'] = $id;
      $viewdisplays[$view-&gt;name]['title'] = $title;
    }
  }
  </code></pre>
  
  <p>Here's the snippet of the form that I'm working with:</p>
  
  <pre><code>$form['view'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Select the view to be used for display'),
    '#options' =&gt; $viewnames,
  );
  $form['view_display'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Select the display of the gallery view to be used'),
    '#options' =&gt; array(),
  );
  </code></pre>
  
  <p>What I want to do, is dynamically fill the view_display select box with the appropriate values.  If the user selected "My Favorite View" from the 'view' select, I want to display the $viewdisplays['My Favorite View'] array as the #options to the 'view_display' field.</p>