473,401 Members | 2,146 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,401 software developers and data experts.

How to show dependent drop down list in forms?

I'm using two drop down list in a form. I have generated the first drop down list from MySQL database with the help of PHP. When i select an option from first drop down list, i have to generate second drop down list options by the selected value of first drop down list from MySQL database.

For example, the first drop down list contains Animals, Birds... If i select the Animal option, the second drop down list should show like Lion, Tiger....

Both lists should be geneted from database only. Any script available for this?
What I have to do? Any one can help me?!
Oct 8 '06 #1
1 6441
monamac
12
one way to approach this would be to refresh the page after the first dropdown item is selected by automatically submitting the form on the page to itself. for example:

<select name="category" onchange="document.forms['yourForm'].action='thisPhpFile.php';document.forms['yourForm'].submit();">
<option>animals</option>
<option>birds</option>
</select>

----------------

and at the top of the page you have some php that checks the 'category' parameter and selects from the correct database table accordingly:

if ($_POST['category'])
$category = $_POST['category'];

if ($category != '') {
$sql = "SELECT * FROM mytable WHERE category = '".$category."'";
(etc, etc, etc...)
}


and then build your second dropdown from that query, while setting the appropriate category on the first dropdown to be "SELECTED".
-----------------

i suppose another way to do it (depending on the amount of information you're dealing with) without refreshing the page would be to create a bunch of javascript arrays at the top of the page with your php, and then either:
1) dynamically build the second dropdown using javascript after the first dropdown has been selected or
2) build a bunch of dropdowns that are hidden and just show the appropriate one when the first dropdown has been selected.

however, if the arrays are too big, i would not recommend this method.

hope this helps.
Oct 9 '06 #2

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

Similar topics

0
by: Dec | last post by:
Ok to simplify things I'll just give an example. This is pretty much what I want to do (minus the postcode): http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF I have relatively little...
1
by: Dec | last post by:
Ok to simplify things I'll just give an example. This is pretty much what I want to do (minus the postcode): http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF I have relatively little...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
10
by: lorirobn | last post by:
Hi, I have a form with several combo boxes, continuous form format, with record source a query off an Item Table. The fields are Category, Subcategory, and Color. I am displaying descriptions,...
5
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
2
by: RAM | last post by:
I need to have two drop down lists in a edited row of a data list. One drop down list should contain Groups and the second one should contain Materials from *selected* group. Thus, I have written:...
1
by: inbamca | last post by:
Hi, Functionality is like when pressing 'CTRL+click' on drop down list in the main jsp page, a popup window appears with a list box contains all the values of the drop down clicked on the main page....
4
by: deanndra | last post by:
First, I want to say thank you to Scott and the others who replied to my first post here. I had to put that database on hold for the moment when I was tasked with a new one. I am building another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.