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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.