Dependent Term Reference Autocomplete I want to make the options for a (secondary) term reference autocomplete field dependent on the values chosen in another (primary) autocomplete term reference field. How can I limit the options in the secondary term reference field? 

I have two vocabularies called chapter and sub-chapters. In the sub-chapters vocabulary, I have an additional term reference field linking each sub-chapter to the chapter in the chapter vocabulary. (I wanted to use two separate vocabularies, rather than a single hierarchical vocabulary to make it easier to use separate exposed views filters).

On my main content form, I want to limit the sub-chapters available in the autocomplete field to the values chosen in the primary chapters autocomplete field. 

I have looked at many different modules for achieving this and haven't found any that will work with my scenario so need to write some code to achieve this. I need to use autocomplete fields as there are so many terms to choose from for both the primary and secondary fields. I have been using the autocomplete deluxe widget for the primary field but I can just use the standard autocomplete widget if this makes it easier.

Can anyone give me a rough outline of the basic code I would need to write in order to achieve this? 

I guess there will need to be an update of the options of the secondary term reference field whenever the values are altered in the primary term reference field using AJAX?
The basic process would be to make the 2nd field an Ajax (AHAH) created field.  Then in this method, set the #autocomplete render element to a URL that uses the first field's value.  Something like:

function simple_ahah_select($form_state) {
if ($form_state['storage']['content']['simple_select_parent']) {
  $element = array(
    '#type' =&gt; 'textfield',
    '#size' =&gt; '60',
   // Define a autocomplete_path depend on the value selected on the parent select field
    '#autocomplete_path' =&gt; 'simple/autocomplete/' . $form_state['storage']['content']['simple_select_parent']
  );
  }
}
return $element;


The Autocomplete URL can probably be a view if you don't want to write code.  But code would be faster.

See this d.o page for some more details