473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dependant Queries for List/Menus in a Form

I'm using SQL databases to populate List/Menus in a form.

What I need some advice on is as follows.

The user selects an entry from the first List/Menu that is filled from a an SQL database, which will then narrow the selection for the next List/Menu that is filled from a another SQL database.

How do I make the query to fill the second List/Menu automatically follow the outcome of the first List/Menu, and so on?

Any advice would be much appreciated.
May 4 '07 #1
2 2915
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

Depending on how you wish to do this, this may be purely a javascript problem.

Do you want to make requests to the server to get the smaller data set or just load all the data on page load?
May 4 '07 #2
I have run into this same issue in some of my programs. My solution may not be terribly elegant, but it works like a charm.

Using a car example, say we have Ford and Toyota vehicles. I run a query that returns all vehicles complete with make and model. I then loop through it, creating a list of arrays with the info I want.

Expand|Select|Wrap|Line Numbers
  1. <cfloop query="qryGetModels">
  2.    <cfset formSelectData = ListAppend(formSelectData, "new Array('#make#','#model#','#modelID#')")>
  3. </cfloop>
To dynamically change the values in a list of models based on whether they select Ford or Toyota, I generate some JavaScript on page load that creates a javascript array of arrays with the information from my query and a function that is called by an onChange event associated with the makes select HTML element (<select name="make" onchange="showModels()">)

Expand|Select|Wrap|Line Numbers
  1. vehicles = new Array(<cfoutput>#formSelectData#</cfoutput>);
  2.  
  3.     function showModels() {
  4.       var makes = document.forms[0].make;
  5.       var models = document.forms[0].model;
  6.       models.options.length = 0;
  7.       for (i = 0; i < vehicles.length; i++) {
  8.         if (vehicles[i][0] == makes.options[makes.selectedIndex].value) {
  9.           models.options[models.options.length] = new Option(vehicles[i][1],vehicles[i][2]);
  10.         }
  11.       }
  12.     }
Now when a user clicks on "Ford" or "Toyota" in the makes select, the models select cleared and then populated with all Ford or Toyota models.

Here is an example of what my javascript "vehicles" variable/array looks like:

Expand|Select|Wrap|Line Numbers
  1. vehicles = new Array(new Array('Ford','Taurus','1'), new Array(new Array('Ford','Explorer','2'), new Array(new Array('Toyota','Avalon','3'), new Array(new Array('Toyota','Yaris','4'));
Like I say, it might not be elegant, but it works!
May 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: nadia | last post by:
I am have used php to create a two sets of arrays of listboxes, each of the listbox in the array have a unique ID. One of the list boxes are dependant on the other one. I have written the code in...
1
by: cefrancke | last post by:
I have set the Startup properties to the following... All menus, toolbars, etc are turned off plus these are unchecked Allow Full Menus Allow Built-in Toolbars Allow Default Shortcut Menus...
0
by: cefrancke | last post by:
I recently discovered, that if you set the startup options for "security", you will have alot of work do to get Access back to "normal". If you disable the built-in menus/toolbars you'll have to...
2
by: allyn44 | last post by:
HI--a simple question about access security--am having brain lock--if I make queries read only to a chosen user group (as defined by access security) will they stil be able to open forms based on...
1
by: Christina | last post by:
Hi, I've been looking at some code for dependent list boxes to adapt to a State and City list. There will only be 2 states for the first list box, and 3 cities in the second list box. When the...
7
chunk1978
by: chunk1978 | last post by:
hello. so i have 2 select menus which add and remove options from a 3rd select menu... it seems, however, that it's not possible to use different select menus to toggle a 3rd, because when an...
5
by: BA | last post by:
Hi there I am trying to write an "application" in Access 2000, that displays a front end and allows the user to interact with the database without seeing Access loaded, in the background, nor on...
1
by: ATS | last post by:
Hi, I, and some collegues of mine, are running into a weird problem with Access 2003. If I want to define a new query (or want to add a table or query to an existing query), Access shows a...
1
by: eHaak | last post by:
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.