Jump to content
Larry Ullman's Book Forums

Is That Possible To Create A Dynamic Select Menu For Category, And Subcategory?


Recommended Posts

Hi, Larry


In your Modern Javascript book,  there is a dynamic select menu for picking operation system. Is that possible to create a similar menu in php? or manipulate that menu with php.


 


I have 2 tables


 


table 1: category contains category_id, category


 


table 2: category_categories contains id, category_id, parent_id


 


so I want to create a primary menu to have all categories that the parent_id equals to 0 (the top), when user select a category from primary menu, the subcategory menu become selectable and load the subcategory under the primary category that user has selected.


 


Thank you all

Link to comment
Share on other sites

If you want to do it without reloading the page, you have to use JavaScript (or Flash, or some other client-side language).

You can do something similar in PHP, but you'll have to create a way for the user to submit the form after selecting something from the first menu, and then completely reload the page to populate the second menu. Again, it's possible in PHP only, but not as smooth.

Link to comment
Share on other sites

hi, HartleySan, thank you for replying, and sorry for the duplicated post.  :mellow: 

 

I tried to modify the menu script that Larry wrote in his Modern Javascript  book and to hook up with php script for supplying the data into the options array. However I was only able to do that for the top category menu. The subcategory menu, as you mentioned, is very difficult to do so. Is that possible to achieve the dynamic menu with Ajax? I haven't studied Ajax yet, so I am not sure how much Ajax can do. Please let me know and thank you again.

Link to comment
Share on other sites

Yes, you definitely can do that with Ajax.

Because Ajax is so essential these days, I recommend taking the time to try and learn how to do what you want to do with Ajax, but if you want to "hack" it a bit, you could just print out all the secondary menus to the HTML, hide them all with CSS, and then make one in particular show up when a certain item is selected from the primary menu.

 

Doing that would require JavaScript, but not Ajax.

Link to comment
Share on other sites

 Share

×
×
  • Create New...