Welcome Guest, Not a member yet? Register   Sign In
helper for double drop-down menus using mysql database
#1

[eluser]Daniel Moore[/eluser]
Not long ago, I needed to use HTML <select with <option statements to create a double drop-down menu, you know, the kind where you select from the first one, and the second one is populated with data accordingly.

The catch is, I needed it to populate from database tables, two tables where the second table had a field that cross referenced the primary key of the first table.

Sounded easy enough, but then I wanted it customizable, not hard-coded for a one-time use. After a few hours of good, hard laboring at the keyboard, I have come up with a great solution.

It's not a plug-in or a class library. It's a helper. It uses Ajax. I don't even put my name in any of the files, because I don't really care about who gets credit for it. I just want to share it, because I've known a few other programmers looking for something similar, so I tried to make it meet everyone's needs as best I could.

There are two main functions that need to be used to produce the HTML output for the drop-downs. One for the source drop-down and one for the target drop-down.

The ddmenu_source_selector() function returns the actual value of from the <option value= to allow you to pre-populate the second drop-down if you wish, which is optional.

Just need to configure the db_config.php file, and make sure you tell the other files "where" you put it, so that it can be found.

There is not enough space in this post for me to post the code.
It can be found here ->ddmenu_helper.zip

This is not CodeIgniter specific, although I would love to see someone set up instructions on how to integrate it as a CodeIgniter helper. Shouldn't be difficult at all.

The documentation is not all there, although there is comments where needed to explain complex functions, and most of it is self-explanatory, and it has an example index.php to give an example of how to use it.

I would be interested in feedback on this, as this is the first time I have ever contributed to this community.
#2

[eluser]cytech[/eluser]
hello, i have read your article and source code about dropdown, i think that was great. but when i use your code, i dont know where to get value from both dropdown,i need to send the value with html form with post method. can you help on this? sorry for bad english, thanks before.
#3

[eluser]Daniel Moore[/eluser]
I'm not quite sure what you are asking here. Can you give a bit more detail on what you are trying to do?

The value for the dropdown boxes come from database tables, which you must configure in the db_config.php file.

Look at the index.php file as an example to see how it is used. This might help. It is not ready to run until you set up the db_config.php file and set up tables with values.
#4

[eluser]cytech[/eluser]
i mean the selected value from dropdown
#5

[eluser]Daniel Moore[/eluser]
The default values for source and target drop down menus are $_POST['sourceList'] and $_POST['targetList'].

If you read through the function definitions in the ddmenu_helper.php file, you will find that this can be changed in ddmenu_target_selector() and ddmenu_source_selector() by passing in an optional parameter.

You might want to check out the function definitions for each function in ddmenu_helper.php, as they are highly configurable. You will find that mysql_dropdown_selector() is a handy function to have whether or not you ever need to use it with the menu system.
#6

[eluser]chipowski[/eluser]
Thanks for posting this code. I have it working fine but how do I actually use the selected item in the second menu?
Is there a parameter that refers to it?

For example, on selecting an item in the second menu, I would like to use a submit button to send the value onto another php page.
#7

[eluser]Juan Velandia[/eluser]
Hello Daniel. I've downloaded the code and I'll check it. I was looking for a solution about this matter not long ago... and I came up with a non optimal solution, I hope it works for me! thanks!
#8

[eluser]chipowski[/eluser]
Please ignore my previous question I managed to figure this out.

Daniel many thanks for your code. It is absolutely perfect for what I am trying to do.
#9

[eluser]gigas10[/eluser]
I haven't looked at this yet, but does this scale for more than 2 dropdown boxes? I have some applications that are 10 or more cascading dropdown's.




Theme © iAndrew 2016 - Forum software by © MyBB