[eluser]doubleplusgood[/eluser]
Hello,
I'm trying to do a database-driven chained select menu, with Manufacturers and Models.
Currently, I have a vehicles_model.php that is simply grabbing all of the Manufacturers and Models as follows;
Code:
public function getManufacturers(){
$this->db->order_by("name", "asc");
$query=$this->db->get('manufacturers');
if($query->num_rows()>0){
// return result set as an associative array
return $query->result_array();
}
}
public function getModels(){
$this->db->order_by("name", "asc");
$query=$this->db->get('models');
if($query->num_rows()>0){
// return result set as an associative array
return $query->result_array();
}
}
My controller looks like this;
Code:
$data['manufacturers'] = $this->vehicles->getManufacturers();
$data['models'] = $this->vehicles->getModels();
$this->load->view('account/add', $data);
And my page is currently displaying two independent select menus as so;
Code:
<div><div class="label">Manufacturer:</div>
<select name="manufacturer">
<option value="-">-</option>
<?php foreach($manufacturers as $item) : ?>
<option value="<?php echo $item['id']?>"><?php echo $item['name']?></option>
<?php endforeach; ?>
</select></div>
<div><div class="label">Model:</div>
<select name="model">
<option value="-">-</option>
<?php foreach($models as $item) : ?>
<option value="<?php echo $item['id']?>"><?php echo $item['name']?></option>
<?php endforeach; ?>
</select></div>
As the post title suggests, I want to be able to display relevant Models in the 2nd select menu, based on the Manufacturer selected in the first select box.
I was wondering if anyone has any advice on how I could accomplish this?, presumably with jQuery.
Thank you.