Welcome Guest, Not a member yet? Register   Sign In
Dynamic chained select menus
#1

[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>
        &lt;?php foreach($manufacturers as $item) : ?&gt;
        <option value="&lt;?php echo $item['id']?&gt;">&lt;?php echo $item['name']?&gt;</option>
        &lt;?php endforeach; ?&gt;
    </select></div>

    <div><div class="label">Model:</div>
        <select name="model">
            <option value="-">-</option>
            &lt;?php foreach($models as $item) : ?&gt;
            <option value="&lt;?php echo $item['id']?&gt;">&lt;?php echo $item['name']?&gt;</option>
            &lt;?php endforeach; ?&gt;
        </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.


Messages In This Thread
Dynamic chained select menus - by El Forum - 04-22-2010, 02:59 AM
Dynamic chained select menus - by El Forum - 04-22-2010, 06:05 AM
Dynamic chained select menus - by El Forum - 04-22-2010, 08:49 AM
Dynamic chained select menus - by El Forum - 06-22-2010, 07:30 AM
Dynamic chained select menus - by El Forum - 06-22-2010, 08:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB