1
votes

I have created custom module for magento admin.There is a form that have 2 drop-downs(one for category and second for its subcategory).How can I relate theme.I want all sub categories in second drop-down on change of first dropdown(state,city like).How can I do this in magento using jquery/ajax.

1

1 Answers

1
votes

here i am giving idea to how to get sub category list from ajax call. you should have to try with your self to call ajax on the change event of main category list and get from below code to generate sub category list.

<select id="category" class="myinput-text required-entry widthinput" name="category">
<?php
  $parentid=5; // parent id which you want sub category
  $categories=explode(',',Mage::getModel('catalog/category')->load($parentid)->getChildren());
  foreach($categories as $cat){ 
     $category=Mage::getModel('catalog/category')->load($cat);
?>
   <option value="<?php echo $category->getId();?>"><?php echo $category->getName();?></option>
<?php } ?>
</select>

hope it will sure help you.