• Advertisement
Sign in to follow this  

[web] PHP dynamic drop down

This topic is 4168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some troubles with dynamic drop downs. I have one drop down, and the option selected generates values in a second drop down using a MySQL query. This is achieved by entering the first selected option into ha hidden field in a hidden form and the submitting it, the values is then recieved by $_POST and used to populate the second drop down list. However. This resets all previously selected fields in the form. I would really much avoid this from happening. Any suggestions ?

Share this post


Link to post
Share on other sites
Advertisement
I pressume from your description that your using javascripts onChange function to automatically submit the page.

You could use session variables to do what your after (if your just wanting to see what the previous selection was), but that would be kinda fiddly.

Id suggest looking at this I had a similar question a few months ago, and this proved rather useful.

I hope this helps

Share this post


Link to post
Share on other sites
Quote:
Original post by Sonnenblume
Id suggest looking at this I had a similar question a few months ago, and this proved rather useful.


That won't work. In that example, all possible entries are pregererated in a js file. Instead I suggest you look into AJAX. Use the first dropdown to send a request to the server for the contents of the second form, then await the response and fill the second form with it. It's not too hard to do once you understand the basics.

[Edited by - Sander on September 22, 2006 12:34:34 AM]

Share this post


Link to post
Share on other sites
While this isn't ideal, you could generate all drop menus and simply hide/display the appropriate ones when the first list has an item selected. This would eliminate using AJAX, but the downer is having a lot of extra HTML that is only used when needed. Again, not ideal but it works.

Share this post


Link to post
Share on other sites
Out of interest, did you refer to a specific AJAX tutorial to achieve this? If so, I would be interested to see how its done as AJAX is something thats of interest to me.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement