MarioPro
07-27-2002, 06:09 PM
Hi,
I'm having a problem o coding a feature that would enable to dynamically load selectboxes using PHP and Javascript.
My problem is on Javascript and not on PHP.
Thanks in advance for any help.
MarioPro
Here's what I would like to do:
<!--### The Data ###-->
Populate selectboxes dynamically for the following information, which is directly related in my database with ID's.
HTML
1st. Selectbox: County
2nd. Selectbox: City
3rd. Selectbox: Location
PHP/MySQL
$county_ID (Table counties)
$county (Table counties)
$city_ID (Table cities)
$city (Table cities)
$location_ID (Table locations)
$location (Table locations)
<!--### The Objective Explained ###-->
Once the user selects the County, the City and Location selectboxes would be populated with the data corresponding to the County selected, without reloading the page.
<!--### The Main SelectBox Schema ###-->
Select your county:
<SELECT NAME="cnt[county]">
<OPTION VALUE="Any">Any</OPTION>
<?
// Selects the county and populates it even
// if the table is updated
$query = "SELECT * FROM counties";
$result = mysql_query($query);
while($rowCnt = mysql_fetch_array($result)){
echo '<OPTION VALUE="'.$rowCnt['ID'].'" ';
// Set the selected county from the earlier search if any
if($rowCnt['ID'] == $cnt['county']){
echo ' SELECTED ';
}
echo '>'.$rowCnt['county'].'</OPTION>'."\n";
}
?>
</SELECT>
Select your City:
<SELECT NAME="c[city]">
<OPTION VALUE="Any">Any</OPTION>
<?
// Selects the city and populates it even
// if the table is updated
$query = "SELECT * FROM cities WHERE county_ID='".$f['county']."'";
$result = mysql_query($query);
while($rowC = mysql_fetch_array($result)){
echo '<OPTION VALUE="'.$rowC['ID'].'" ';
// Set the selected city from the earlier search if any
if($rowC['ID'] == $c['city']){
echo ' SELECTED ';
}
echo '>'.$rowC['city'].'</OPTION>'."\n";
}
?>
</SELECT>
Select your City:
<SELECT NAME="l[location]">
<OPTION VALUE="Any">Any</OPTION>
<?
// Selects the location and populates it even
// if the table is updated
$query = "SELECT * FROM locations WHERE city_ID='".$f['city']."'";
$result = mysql_query($query);
while($rowL = mysql_fetch_array($result)){
echo '<OPTION VALUE="'.$rowL['ID'].'" ';
// Set the selected location from the earlier search if any
if($rowL['ID'] == $l['location']){
echo ' SELECTED ';
}
echo '>'.$rowL['location'].'</OPTION>'."\n";
}
?>
</SELECT>
I'm having a problem o coding a feature that would enable to dynamically load selectboxes using PHP and Javascript.
My problem is on Javascript and not on PHP.
Thanks in advance for any help.
MarioPro
Here's what I would like to do:
<!--### The Data ###-->
Populate selectboxes dynamically for the following information, which is directly related in my database with ID's.
HTML
1st. Selectbox: County
2nd. Selectbox: City
3rd. Selectbox: Location
PHP/MySQL
$county_ID (Table counties)
$county (Table counties)
$city_ID (Table cities)
$city (Table cities)
$location_ID (Table locations)
$location (Table locations)
<!--### The Objective Explained ###-->
Once the user selects the County, the City and Location selectboxes would be populated with the data corresponding to the County selected, without reloading the page.
<!--### The Main SelectBox Schema ###-->
Select your county:
<SELECT NAME="cnt[county]">
<OPTION VALUE="Any">Any</OPTION>
<?
// Selects the county and populates it even
// if the table is updated
$query = "SELECT * FROM counties";
$result = mysql_query($query);
while($rowCnt = mysql_fetch_array($result)){
echo '<OPTION VALUE="'.$rowCnt['ID'].'" ';
// Set the selected county from the earlier search if any
if($rowCnt['ID'] == $cnt['county']){
echo ' SELECTED ';
}
echo '>'.$rowCnt['county'].'</OPTION>'."\n";
}
?>
</SELECT>
Select your City:
<SELECT NAME="c[city]">
<OPTION VALUE="Any">Any</OPTION>
<?
// Selects the city and populates it even
// if the table is updated
$query = "SELECT * FROM cities WHERE county_ID='".$f['county']."'";
$result = mysql_query($query);
while($rowC = mysql_fetch_array($result)){
echo '<OPTION VALUE="'.$rowC['ID'].'" ';
// Set the selected city from the earlier search if any
if($rowC['ID'] == $c['city']){
echo ' SELECTED ';
}
echo '>'.$rowC['city'].'</OPTION>'."\n";
}
?>
</SELECT>
Select your City:
<SELECT NAME="l[location]">
<OPTION VALUE="Any">Any</OPTION>
<?
// Selects the location and populates it even
// if the table is updated
$query = "SELECT * FROM locations WHERE city_ID='".$f['city']."'";
$result = mysql_query($query);
while($rowL = mysql_fetch_array($result)){
echo '<OPTION VALUE="'.$rowL['ID'].'" ';
// Set the selected location from the earlier search if any
if($rowL['ID'] == $l['location']){
echo ' SELECTED ';
}
echo '>'.$rowL['location'].'</OPTION>'."\n";
}
?>
</SELECT>