jessentha Posted December 9, 2014 Share Posted December 9, 2014 Hi, I need help in populating data from DB in the 2nd listbox depending on 1st listbox data (where the data of 1st listbox is also fetched from DB), in the same form. Thanks, Jessentha Quote Link to comment https://forums.phpfreaks.com/topic/292991-populating-data-from-db-in-the-2nd-listbox-depending-on-1st-listbox/ Share on other sites More sharing options...
sKunKbad Posted December 9, 2014 Share Posted December 9, 2014 So you will need to use AJAX. First, all you need to do is populate the first dropdown when the page loads. Use javascript to detect when a change is made in the first dropdown. When the chance is made, use AJAX to send the values to the server with a response of the values for the second dropdown. Quote Link to comment https://forums.phpfreaks.com/topic/292991-populating-data-from-db-in-the-2nd-listbox-depending-on-1st-listbox/#findComment-1499109 Share on other sites More sharing options...
jessentha Posted December 10, 2014 Author Share Posted December 10, 2014 Thanks for helping ... Quote Link to comment https://forums.phpfreaks.com/topic/292991-populating-data-from-db-in-the-2nd-listbox-depending-on-1st-listbox/#findComment-1499202 Share on other sites More sharing options...
Psycho Posted December 10, 2014 Share Posted December 10, 2014 Well, I would say you *may* need to use AJAX. You really have three options: 1. Create a process for the user to select an option in the first select list and do a submission to have the page release with the first selection and the second select list populated with the relevant values. This isn't a great user experience, but it is easy and a good place to start since you need all the same code/logic as a base. 2. Create a JavaScript only solution. If the total amount of data for the primary and secondary options is not humongous, you can extract all the options from the database when the page loads and write the data into JavaScript variables. Then you can control the select list using just JavaScript. The benefit of this is that the functionality will not be impacted by any momentary connectivity delays. But, if the amount of data is huge, it could slow the time for the page to load. 3. Use AJAX. You would use the same JavaScript logic to manage the select list, but instead of getting the data from local JavaScript variables, make a request to the server to get the list of values for the 2nd select list when a change is made, For options 2 & 3 I would highly suggest using JQuery. There are plenty of 3rd party plug-ins for JQuery to do what you want. Here is one example: http://www.appelsiini.net/projects/chained/demo.html Quote Link to comment https://forums.phpfreaks.com/topic/292991-populating-data-from-db-in-the-2nd-listbox-depending-on-1st-listbox/#findComment-1499208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.