[eluser]moriokasan[/eluser]
You are perfectly right, thank you! I resolved my issue today and I wanted to post the solution here, anyway, for others. It seems that a rested brain is a lot better than a sleepy one. So here is the solution that works (it is just a simple example)
Controller:
Code:
function index()
{
//check session
$this->load->library('Mysession');
if ($this->mysession->isInactive($this)) return;
$this->load->model('crud2_model');
if($query2 = $this->crud2_model->select_all('select p.id, p.name from expenses_providers p order by p.name asc'))
{
$data['providers'] = $query2;
}
else
{
$data['providers'] = array();
}
$this->load->view('test/dropdown', $data);
}
function getproducts()
{
//check session
//$this->load->library('Mysession');
//if ($this->mysession->isInactive($this)) return;
$this->load->model('crud_model');
$query2 = $this->crud_model->select_all_for_parentid('expenses_products', 'providerid', $this->uri->segment(4));
foreach($query2 as $result)
{
echo "<option value=".$result->id.">".$result->name."</option>";
}
}
Then the view looks like this
Code:
[removed]
function refresh_products(){
var selected_provider = $('#providers option:selected').val();
$('#products').load("/test/dropdown/getproducts/"+selected_provider);
}
$(document).ready(function(){
refresh_products();
$('#providers').change(refresh_products);
});
[removed]
</head>
<body>
<h1> testing jquery dropdown in cascade</h1>
<input type="text" id="debug">Debug text</input><br></br>
<select id="providers" name="providers">
<?php if(isset($providers)) : foreach($providers as $provider) : ?>
<option value=<?php echo $provider->id; ?>>
<?php echo $provider->name; ?>
</option>
<?php endforeach; endif; ?>
</select>
<select id="products" name="products">
</select>
</body>
I hope this helps someone!
All the best!
Marius