473,383 Members | 1,795 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,383 software developers and data experts.

Multiple Dynamic Drop Down Population

Greetings:

I have a table with 3 pieces of data that I would like to use to
dynamically populate 3 drop downs using javascript. The fields are
state, orgname, office. If it's not already obvious, I'd like orgname
drop down to change when a state is selected and I would like office
drop down to change when an orgname is selected. I can do this with
multiple tables but am having difficulty getting it to work when the
data is in the same table. Below is the code to get state and orgname
from separate tables(the code reflects one table and is broken in the
below state). It's the best I can come up with and I can see why it
doesn't work but I know there must be a way to pull all the pieces from
a single table. Advice is much appreciated.

<code>
$list=$_SESSION['list'];
if(isset($list) and strlen($list) 0){
$quer=mysql_query("SELECT DISTINCT orgname,org_id FROM organization
WHERE state=$list ORDER BY orgname");
}else{$quer=mysql_query("SELECT DISTINCT orgname FROM organization ORDER
BY orgname"); }
$quer2=mysql_query("SELECT DISTINCT state FROM organization ORDER BY
state");

//first drop down
echo "<select name='state' onchange=\"reload(this.form)\"><option
value='0'>Select one</option>";
while($state = mysql_fetch_array($quer2)) {
if($state['org_id']==@$list){echo "<option selected
value='$state[state]'>$state[state]</option>"."<BR>";}
else{echo "<option value='$state[state]'>$state[state]</option>";}
}
echo "</select>";

//next drop down
echo "<select name='org'><option value=''>Select one</option>";
while($org = mysql_fetch_array($quer)) {
echo "<option value='$org[org_id]'>$org[orgname]</option>";
}
echo "</select>";
</code>

--

Regards,

Jeff Gardner
___________________________

"Contrary to popular belief, Unix is user friendly. It just happens
to be very selective about who its friends are." --Kyle Hearn
Sep 10 '06 #1
1 3574
Personally i think the best way would be ajax, and there is a million
ways to accomplish it in ajax. Here is a really simple bare bones
example. Like i said this is not the only way to do it but it is pretty
straight forward.

Example:
http://developer.apple.com/internet/...e/example.html
Tutorial:
http://developer.apple.com/internet/...mlhttpreq.html
Jeff Gardner wrote:
Greetings:

I have a table with 3 pieces of data that I would like to use to
dynamically populate 3 drop downs using javascript. The fields are
state, orgname, office. If it's not already obvious, I'd like orgname
drop down to change when a state is selected and I would like office
drop down to change when an orgname is selected. I can do this with
multiple tables but am having difficulty getting it to work when the
data is in the same table. Below is the code to get state and orgname
from separate tables(the code reflects one table and is broken in the
below state). It's the best I can come up with and I can see why it
doesn't work but I know there must be a way to pull all the pieces from
a single table. Advice is much appreciated.

<code>
$list=$_SESSION['list'];
if(isset($list) and strlen($list) 0){
$quer=mysql_query("SELECT DISTINCT orgname,org_id FROM organization
WHERE state=$list ORDER BY orgname");
}else{$quer=mysql_query("SELECT DISTINCT orgname FROM organization ORDER
BY orgname"); }
$quer2=mysql_query("SELECT DISTINCT state FROM organization ORDER BY
state");

//first drop down
echo "<select name='state' onchange=\"reload(this.form)\"><option
value='0'>Select one</option>";
while($state = mysql_fetch_array($quer2)) {
if($state['org_id']==@$list){echo "<option selected
value='$state[state]'>$state[state]</option>"."<BR>";}
else{echo "<option value='$state[state]'>$state[state]</option>";}
}
echo "</select>";

//next drop down
echo "<select name='org'><option value=''>Select one</option>";
while($org = mysql_fetch_array($quer)) {
echo "<option value='$org[org_id]'>$org[orgname]</option>";
}
echo "</select>";
</code>

--

Regards,

Jeff Gardner
___________________________

"Contrary to popular belief, Unix is user friendly. It just happens
to be very selective about who its friends are." --Kyle Hearn
Sep 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
1
by: seanmayhew | last post by:
Im attempting to get the vaules for the second drop down on index changed of the first. This works fine. However rather than just replacing the values of the second drop down with the new values...
2
by: jagdishl | last post by:
hi I have to populate the second drop down list based on the selection made in the previous drop down list.I have to chose between two values in the first dropdown list i.e city and county.This is...
3
by: simon | last post by:
hello, i have a form where there are multiple dropdown lists that will all be populated from the same initial data query. i have a vb class defined to make the stored proc call and that returns a...
19
by: mart2006 | last post by:
I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters what is shown in the dynamic menu....
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
3
by: scott | last post by:
Hello all, I am ripping my hair out over this and maybe someone could help. I have a site that has groups and subgroups of those groups that all have int id's. I am trying to have a...
3
by: amcoldspy | last post by:
Hi, am trying to create dynamic drop down boxes.. there are 3 drop down boxes. The second drop down box elements are to be update based on the selection made in the first drop down box...
6
by: Igor | last post by:
Hello I have the following problem. I have three drop down lists on my page. They are filled with data from a database. Initially only the first one is enabled. The next one is enebled when...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.