Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Chained drop down menu using PHP
03-27-2010, 06:08 AM #1
- Join Date
- Mar 2010
- New Jersey USA
- Thanked 4 Times in 4 Posts
Chained drop down menu using PHP
I am trying to create 2 different drop down menus which are chained.
First drop down menu: options 1, 2, 3, and 4
Second drop down menu: options 1, 2, 3 and 4
However for the first drop down menu, if you choose the number then that number cannot be selected again on the second drop down menu. So if i pick 4 on the first drop down. then only 1, 2, and 3 should show up on the second drop down OR if you pick 4 on the second drop down it gives you an error saying you selected that value.
Here is the complicated part that I cannot figure out.
I want each drop down menus on two different pages and not on the same page. So after you select the submit button on the first drop down it should go to another page with the second drop down.. Has anyone seen this before. if you can give me some tips or show me how its done or even a webpage that has already implemented this i would appreciate it.
03-27-2010, 08:19 AM #2
- Join Date
- Jul 2009
- Thanked 7 Times in 7 Posts
Forgetting the dropdown side for now...
The key is to get the data from the first page to the page with the second dropdown. If you can do that skip the next two paragraphs!
The data from the first page is presumably passed to another page (or itself for processing). You could store that data in a session variable or cookie for use on the page with the second drop down.
If the first page leads directly to the second then the second can access that data using $_POST or $_GET.
Once the data is on the second page PHP can change the dropdown before the page is sent. For example you could create the dropdown using a loop to create each OPTIOON element. In that loop only write the new OPTION if the number does not match the data which came from the previous page. Then the user will not even be able to see the number they already picked.