I want to filter the options to display in the second dropdown list ('make') based on selected id from previous dropdown list ('type') instead of displaying all 'make' options.
How do I capture the id of type(first dropdown) in order to display list in make accordingly before the form is submitted?
here's the code:
mysql_select_db($database);
$query="SELECT * FROM car_make";
$result= mysql_query($query)or die(mysql_error());
mysql_select_db($database);
$query_type="SELECT * FROM car_type";
$result_type= mysql_query($query_type)or die(mysql_error());
<tr><td>Choose Car Type</td><td>:</td>//first dropdown (type)
<td>
<select name="type">
<option value="">Please select a car Type</option>
<?php
while($row_type=mysql_fetch_array($result_type))
{
$carType=$row_type['carType'];
$carType_id=$row_type['carType_id'];
?>
<option value="<?php echo $carType_id; ?>"><?php echo $carType; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr><td>Choose Car Make</td><td>:</td>//second dropdown (make)
<td>
<select name="make">
<option value="">Please select a car make</option>
<?php
while($row=mysql_fetch_array($result))
{
$carMake_id=$row['carMake_id'];
$carMake=$row['carMake'];
?>
<option value="<?php echo $carMake_id; ?>"><?php echo $carMake; ?></option>
<?php
}
?>
</select>
</td>
</tr>
You're looking for what's called a chained select. Here's a php/ajax way to do it: