How to modify contents of drupal select form element based on what was selected in a preceeding select element
You can create it with built-in Ajax Framework (you don't need to use javascript). Here is a nice example (and I'll include the code here):

function sandbox_ajax_dropdown($form, &amp;$form_state) {
  $form['sandbox_ajax_dropdown']['province'] = array(
    '#title' =&gt; t('Province'),
    '#type' =&gt; 'select',
    '#options' =&gt; _load_province(),
    '#ajax' =&gt; array(
      'event'=&gt;'change',
      'callback' =&gt;'sandbox_ajax_dropdown_city',
      'wrapper' =&gt; 'city-wrapper',
    ),
  );

 $form['sandbox_ajax_dropdown']['wrapper'] = array(
    '#prefix' =&gt; '&lt;div id="city-wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );

  $options = array('- Select city -');
  if (isset($form_state['values']['province'])) {
    $options = _load_city($form_state['values']['province']);
  }

  $form['sandbox_ajax_dropdown']['wrapper']['city'] = array(
    '#title' =&gt; t('City'),
    '#type' =&gt; 'select',
    '#options' =&gt; $options,
  );

  $form["sandbox_ajax_dropdown"]["submit"] = array(
    "#value"  =&gt; t("Submit"),
    "#type"   =&gt; "submit",
    "#submit" =&gt; array("sandbox_ajax_dropdown_submit"),
  );

  return $form;
}

function sandbox_ajax_dropdown_city($form, $form_state) {
  return $form['sandbox_ajax_dropdown']['wrapper'];
}


function sandbox_ajax_dropdown_city($form, $form_state) {
  return $form['sandbox_ajax_dropdown']['wrapper'];
}

function _load_province() {
  $province = array('- Select province -');
  $query = db_select("sandbox_province", "a");
  $query-&gt;fields("a", array('id', 'name'));
  $query-&gt;condition("a.status", 1);
  $query-&gt;orderBy("a.name");
  $result = $query-&gt;execute();

  while($row = $result-&gt;fetchObject()){
    $province[$row-&gt;id] = $row-&gt;name;
  }

  return $province;
}

function _load_city($province_id) {
  $city = array('- Select city -');
  $query = db_select("sandbox_city", "a");
  $query-&gt;fields("a", array('id', 'name'));
  $query-&gt;condition("a.status", 1);
  $query-&gt;condition("a.province_id", $province_id);
  $query-&gt;orderBy("a.name");
  $result = $query-&gt;execute();

  while($row = $result-&gt;fetchObject()){
    $city[$row-&gt;id] = $row-&gt;name;
  }

  return $city;
}


And also take a look at Examples module.