Jump to content

populating data from DB in the 2nd listbox depending on 1st listbox


jessentha

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.