[eluser]Thiago Leao[/eluser]
Hi guys, I'm trying to dynamically popular.
Select category and subcategory appears registered
Produto (Controller)
Code:
public function ajax_call() {
$data['id'] = $this->input->post('id');
$data = $this->produto_model->get_subcategoria($id);
print form_dropdown('city',$data);
}
Produto_model (MODEL)
Code:
function get_categoria() {
$query = $this->db->query("SELECT * FROM categoria");
if ($query->num_rows > 0) {
return $query->result();
}
}
function get_subcategoria($id) {
$query = $this->db->query("SELECT FROM subcategoria WHERE id_categoria = '{$id}'");
if ($query->num_rows > 0) {
return $query->result();
}
}
VIEW
Code:
$(document).ready(function(){
$(".country").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax
({
type: "POST",
url: "<? echo base_url(); ?>admin/produto/ajax_call",
data: dataString,
cache: false,
success: function(html)
{
$(".city").html(html);
}
});
});
});
<select name="country" class="styled" class="country">
<option selected="selected">Selecione uma categoria</option>
<? foreach($categoria as $listcategoria): ?>
<option value="<?=$listcategoria->id_categoria; ?>"><?=$listcategoria->categoria; ?></option>
<? endforeach; ?>
</select>
<select name="city" class="city">
<option selected="selected">--Select City--</option>
</select>
Could someone help me?
thanks!