Auto Fill Dropdown from Database |
[eluser]codelearn[/eluser]
Hey guys, Got a simple problem here which doesn't seem to work for me. I have a table called "categories" which contains two fields: parent category and a subcategory (IE main category is "Automotive" and a subcat would be "Towing"). It is prefilled with about 20 Automotive subcategories. I need to create a dropdown of categories, and then once one of those is chosen I need to fill the second dropdown with all of the subcategories with that parent. Seems simple enough, but its early (kind of). Thanks for the help.
[eluser]Ahmed Nuaman[/eluser]
Why don't you simply use AJAX? You can use such code for the parent cat dropdown: Code: <? foreach ($cats as $v) { ?> And then using AJAX (such as: http://www.prototypejs.org) you can add the "onchange" attr to the <select> field around the parent categories. That will then run a query, get the sub cats and put them into a second <select> below. |
Welcome Guest, Not a member yet? Register Sign In |