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

Populate drop-down lists from database using PHP and ajax.

1
As an example, my MySQL database has 3 tables: main-area, sub-area, and items. Using PHP I populate my first select-list as follows:
[PHP]<?php
// Create list containing the Main Areas
echo "Select an Area:";

echo "<select name='area_select' id='area_select' onChange='getArea();'>\n";
while ($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<option value=\'$area_id\'>$name\n";
}
echo "</select>\n";
?>[/PHP]
This displays the list correctly. I have set the onChange to the getArea() function from my ajax script.
Expand|Select|Wrap|Line Numbers
  1.             var province = document.getElementById("province_select").value;
  2. var url = "result.php";
  3. request.open("POST", url, true);
  4. request.onreadystatechange = updatePage;
  5. request.send(null);
I am not sure what I should set this function to in order for it to get the sub-areas in the chosen main-area from the database. It must then populate a <div> to contain a second select-list containing these sub-areas.
When I then select the sub-area it should do the same, but this time getting the items available in that sub-areas from the database.

Thanks
Jul 23 '07 #1
1 2648
pbmods
5,821 Expert 4TB
Heya, wradyn. Welcome to TSDN!

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Jul 24 '07 #2

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

Similar topics

3
by: Girish | last post by:
How do i populate a static hastable without the need to instantiate the class? any ideas? Im confused. class VAErrorMap { static Hasttable _ErrorMap = new Hashtable(); public VAErrorMap() {...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
5
by: John A Grandy | last post by:
is it possible to write a vb.net code (intended to run on the client-side) that would invoke an instance of IE, have it download a page from a certain URL, and then pre-populate some of the...
0
by: csgraham74 | last post by:
HI, ive been trying to find a resolution to problem regrding the population of drop downlists dynamiclly. ie. i have their name stored in SQL server and i want to be able to loop through this...
4
by: Nate | last post by:
I am looking to populate a Schedule table with information from two other tables. I am able to populate it row by row, but I have created tables that should provide all necessary information for me...
2
by: Nate | last post by:
I am looking to populate a Schedule table with information from two other tables. I am able to populate it row by row, but I have created tables that should provide all necessary information for me...
1
by: ashok1 | last post by:
Hi friend i have a table which is divided into two part by the help of td now a table have have two column, and i was drag and drop tree view control on the left side of the table, now i want when i...
0
by: xmail123 | last post by:
How to populate a treeview from a dataset I am very new to C#. I need to create a Windows form that will read a SQL table and populate a treeview. I can connect to the DB, create the...
12
by: peerraghu | last post by:
hi i want to populate country's name in 1st dropdownlist and their states should be placed in the 2nd dropdownlist, if we select any state it should place the name of the capital in the textbox...
1
by: Paul | last post by:
I have a table with a list of departments & Dept IDs (table a) and also a master table (table b). When staff are completing an input (this is saved in the master table b) they fill in multiple...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.