Hi everyone,
I'm having difficuties in getting 2 select boxes to automatically update, when a specific option is chosen from the 1st select box, the 2nd box should update accordingly.
I should also point out that i am populating my select boxes from a database.
My database structure is as follows:
Manufacturers
man_id
manufacturer
Models
model_id
man_id
model
For example:
I choose Audi from the 1st select box
I want the second select box to display a list of models for that manufacturer without having to refresh the page.
Below is my code for the select boxes. I'm aware i'll need to use AJAX, i just need a hand getting it set up.
Any help would be greatly appreciated
<select name="man_id" class="input" id="man_id">
<option value="Please Select">Please Select</option>
<?php
// Open Connection to DB
require_once ('../include/config.inc_admin.php');
require_once (MYSQL);
$q = "SELECT man_id, manufacturer FROM manufacturers";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo "<option value=" . $row['man_id'] . ">" . $row['manufacturer'] . "</option>";
}
?>
</select></label></td>
</tr>
<tr>
<td><label>Model:<br />
<select name="model_id" class="input" id="model_id">
<option value="Please Select">Please Select</option>
<?php
// Open Connection to DB
require_once ('../include/config.inc_admin.php');
require_once (MYSQL);
echo $q = "SELECT model_id, model FROM models";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo "<option value=" . $row['model_id'] . ">" . $row['model'] . "</option>";
}
?>
</select>