Magento News

 

Magento: Category Dropdown Boxes in Advanced Search

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 dont just want to list all the subcategories which is what I curently have:

Thanks in advance

<li>
  <select name="model" id="category_search_field1">
    <option value="">-- Model --</option>
    <?php foreach ($this->getStoreCategories() as $_category): ?>
      <?php if($_category->hasChildren()): ?>
        <?php foreach ($_category->getChildren() as $subcategory):
          if($subcategory->getIsActive()) : ?>
            <option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
       <?php endif; endforeach; ?>
      <?php endif; ?
    <?php endforeach ?>
  </select>
</li>

<li>
<label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
                <div class="input-box">
                    <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
                        <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                    </select>
                   <script type="text/javascript">
                   //<![CDATA[
                       $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                   //]]>
                   </script>
                   <input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
               </div>
            </li>
        <?php //endif; ?>`

Magento: Category Dropdown Boxes in Advanced Search

Possibly Related Posts:


 

Leave a Reply