title: Magento: Category Dropdown Boxes in Advanced Search
body: <p>I’m trying to edit my advanced search form to have 2 dropdown boxes: one for a parent category and the 2nd for its subcategories.  Do I need Javascript to populate the 2nd one as I don't just want to list all the subcategories which is what I currently have:</p>
  
  <pre><code>&lt;li&gt;
    &lt;select name="model" id="category_search_field1"&gt;
      &lt;option value=""&gt;-- Model --&lt;/option&gt;
      &lt;?php foreach ($this-&gt;getStoreCategories() as $_category): ?&gt;
        &lt;?php if($_category-&gt;hasChildren()): ?&gt;
          &lt;?php foreach ($_category-&gt;getChildren() as $subcategory):
            if($subcategory-&gt;getIsActive()) : ?&gt;
              &lt;option value="&lt;?php echo $subcategory-&gt;getId(); ?&gt;"&lt;?php echo ($this-&gt;getRequest()-&gt;getQuery('category') == $subcategory-&gt;getId() ? ' selected="selected"': "") ?&gt;&gt;&lt;?php echo $subcategory-&gt;getName(); ?&gt;&lt;/option&gt;
         &lt;?php endif; endforeach; ?&gt;
        &lt;?php endif; ?
      &lt;?php endforeach ?&gt;
    &lt;/select&gt;
  &lt;/li&gt;
  
  &lt;li&gt;
  &lt;label for="region_id"&lt;?php if ($this-&gt;isStateProvinceRequired()) echo ' class="required"' ?&gt;&gt;&lt;?php if ($this-&gt;isStateProvinceRequired()) echo '&lt;em&gt;*&lt;/em&gt;' ?&gt;&lt;?php echo $this-&gt;__('State/Province') ?&gt;&lt;/label&gt;
                  &lt;div class="input-box"&gt;
                      &lt;select id="region_id" name="region_id" title="&lt;?php echo $this-&gt;__('State/Province') ?&gt;" style="display:none;"&lt;?php echo ($this-&gt;isStateProvinceRequired() ? ' class="validate-select"' : '') ?&gt;&gt;
                          &lt;option value=""&gt;&lt;?php echo $this-&gt;__('Please select region, state or province') ?&gt;&lt;/option&gt;
                      &lt;/select&gt;
                     &lt;script type="text/javascript"&gt;
                     //&lt;![CDATA[
                         $('region_id').setAttribute('defaultValue',  "&lt;?php echo $this-&gt;getEstimateRegionId() ?&gt;");
                     //]]&gt;
                     &lt;/script&gt;
                     &lt;input type="text" id="region" name="region" value="&lt;?php echo $this-&gt;htmlEscape($this-&gt;getEstimateRegion()) ?&gt;"  title="&lt;?php echo $this-&gt;__('State/Province') ?&gt;" class="input-text" style="display:none;" /&gt;
                 &lt;/div&gt;
              &lt;/li&gt;
          &lt;?php //endif; ?&gt;`
  </code></pre>