473,698 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to show dependent drop down list in forms?

2 New Member
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 6465
monamac
12 New Member
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="docum ent.forms['yourForm'].action='thisPh pFile.php';docu ment.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
1811
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 experience with databases (hate being a n00b) but I'm currently attempting to put myself through some sort of crash course.. How far have I got? Ok so using MS access 2003. I have a table (table1) with data with a
1
3453
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 experience with databases (hate being a n00b) but I'm currently attempting to put myself through some sort of crash course.. How far have I got? Ok so using MS access 2003. I have a table (table1) with data with a
2
4327
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 there? What about Drag/Drop; is there more than one way for the source to make data available Is it always OLE?
3
10404
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== using System; using System.Drawing; using System.Collections; using System.ComponentModel;
3
6154
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 that appear when user clicks the drop-down arrow button. Because items in the Drop down list are a little long, user can't see the full thing when they pull down the items from the drop down list.
10
9561
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, not ID's, so I have to convert the ID's from various lookup tables. The combo boxes work fine except for subcategory, which is dependent on category. Depending on category, the drop-down box for subcategory will display different items. (for...
5
18724
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 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...
2
2157
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: <asp:SqlDataSource ID="GroupsList" runat="server" ConnectionString="..." SelectCommand="SELECT ID, Name FROM Groups" /> <asp:SqlDataSource ID="MaterialsList" runat="server" ConnectionString="..." SelectCommand="SELECT ID, Name FROM Materials...
1
6776
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. But some times when we expand the drop down and press "CTRL+click" on any of the options in the main jsp, values are not getting populated in the popup window List box. Is any other options to load values from main jsp to popup jsp fle? Pls see...
4
2183
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 database from scratch. This one is for job announcements. I've built only 2 tables (I know this is a no-no, but it was demanded by those wanting this database so I've complied). The field name properties and data types in both tables are virtually...
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7728
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.