[eluser]smilie[/eluser]
someviewfile.php
Code:
<select id="first">
<option value="1">Milk</option>
<option value="2">Sugar</option>
</select>
<div id="second_div">
<select id="second">
<option value="">Please select from the first one...</option>
</select>
</div>
Then (at least I am using jquery - you use any other js / ajax combination) in the
Code:
< script type text/js >
// JS Ajax call to update billing or auto incasso
$("#first").change(function(){
var type = this.val();
// Then, call Ajax to process request :)
$.ajax({
url: "<?php echo base_url();?>somecontroller/somefunction",
type: "POST",
data: ({
type: type,
}),
dataType: "html",
async:true,
success: function(msg){
if(msg)
{
$("#second_div").html(msg);
}
else
{
alert('Could not get any DB data for second select...');
}
}
});
});
< / script>
somecontroller.php
And your somecontroller/somefunction should have:
Code:
function somefunction()
{
$data = $this->db->select('*')->from('second')->where('type',$this->input->post('type'))->get->result_array();
// Prepare drop down box
$dd = '<select id="second">';
foreach($data as $key=>$val)
{
$dd .= '<option value="'.$key.'">'.$val.'</option>';
}
$dd .= '</select>';
echo $dd;
}
Do not forget to include jquery.min.js in your CI
Have fun...
Cheers,
Smilie