title: nested categories dropdown in magento
body: <p>I have the following working code in magento frontend in a form for customer &quot;add a product&quot; functionality that Im developing:</p>
  <p>Helper area:</p>
  <pre><code>public function getCategoriesDropdown() {
  
      $categoriesArray = Mage::getModel('catalog/category')
          -&gt;getCollection()
          -&gt;addAttributeToSelect('name')
          -&gt;addAttributeToSort('path', 'asc')
          -&gt;addFieldToFilter('is_active', array('eq'=&gt;'1'))
          -&gt;load()
          -&gt;toArray();
  
  
      foreach ($categoriesArray as $categoryId =&gt; $category) {
          if (isset($category['name'])) {
              $categories[] = array(
                  'label' =&gt; $category['name'],
                  'level'  =&gt;$category['level'],
                  'value' =&gt; $categoryId
              );
          }
      }
      return $categories;
  }
  </code></pre>
  <p>PHTML File:</p>
  <pre><code>&lt;select id=&quot;category-changer&quot; name=&quot;category-changer&quot; style=&quot;width:150px;&quot;&gt;
          &lt;option value=&quot;&quot;&gt;--Select Categories--&lt;/option&gt;
              &lt;?php
               $_CategoryHelper = Mage::helper(&quot;marketplace&quot;)-&gt;getCategoriesDropdown();
                          foreach($_CategoryHelper as $value){
                              foreach($value as $key =&gt; $val){
  
                                  if($key=='label'){
                                      $catNameIs = $val;
                                  }
                                  if($key=='value'){
                                      $catIdIs = $val;
                                  }
                                  if($key=='level'){
                                      $catLevelIs = $val;
                                      $b ='';
                                      for($i=1;$i&lt;$catLevelIs;$i++){
                                          $b = $b.&quot;-&quot;;
                                      }
                                  }
                              }
                              ?&gt;
                &lt;option value=&quot;&lt;?php echo $catIdIs; ?&gt;&quot;&gt;&lt;?php echo $b.$catNameIs ?&gt;&lt;/option&gt;
                          &lt;?php
                          }
                          ?&gt;
                      &lt;/select&gt;
  </code></pre>
  <p>this code generates a dropdown with categories and subcategories. like this one:
  <img src="https://i.stack.imgur.com/cg8cS.png" alt="enter image description here" /></p>
  <p>my main idea is to create n level nested chained dropdowns for subcategories like this example:
  <img src="https://i.stack.imgur.com/HjiPe.png" alt="enter image description here" /></p>
  <p>or this layout would be better:
  <img src="https://i.stack.imgur.com/rO0RR.gif" alt="enter image description here" /></p>
  <p>any guidance or code example to modify the proposed php in order to include an ajax call, or javascript to generate those frontend chained frontends will be appreciated</p>
  <p>brgds!</p>