Welcome Guest, Not a member yet? Register   Sign In
Auto Fill Dropdown from Database
#1

[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.
#2

[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) { ?>
<option value="&lt;?=$v-Id;?&gt;">&lt;?=$v-Name;?&gt;</option>
&lt;? } ?&gt;

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.




Theme © iAndrew 2016 - Forum software by © MyBB