CodeIgniter Forums
Required Ajax Dropdown to fetch Categories & subcategories both from Database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Required Ajax Dropdown to fetch Categories & subcategories both from Database (/showthread.php?tid=23796)



Required Ajax Dropdown to fetch Categories & subcategories both from Database - El Forum - 10-22-2009

[eluser]Unknown[/eluser]
Hi Guys,

I would be really thankful if you can tell me how to fetch categories and associated sub categories in drop down from database without Page Re-load (using ajax).

I have a categories drop down in which i have fetched all categories from table : categories

Now, what I want is that when a user selects a category, subcategories should be displayed in drop down in which all the subcategories would be coming from table against selected category id. I need to implement this in CodeIgniter.

PLEASE HELP!


Required Ajax Dropdown to fetch Categories & subcategories both from Database - El Forum - 10-22-2009

[eluser]Ben Edmunds[/eluser]
There are several ways of doing this.

The way I would choose is to do an ajax request [.request()] with the chosen main category to a controller that interacts with a model and return the sub-category items.

If you are using JQuery then the function is ajax(). If you are using something other than JQuery just research AJAX request with whatever your using, whether that be straight javascript or another framework.


Required Ajax Dropdown to fetch Categories & subcategories both from Database - El Forum - 10-22-2009

[eluser]mattpointblank[/eluser]
To make it slightly quicker, you could display all of the subcategory dropdowns, use javascript to hide them on page load, then show the relevant one when the user selects an option from the category list.