Need help to every body why wrong with my code i want to make a two dropdown,. one drop down to master data and second dropdown to child from data master.. if i cannot make .chzn-select from jquery it's never mind but if action edit the child data the respone is wrong,. and then i make .chzn-select but nothing respone, this is my code :
/My view //the jquery.min.js and chosen.jquery.js and chosen.css has been loaded
<script type="text/javascript">
$(".chzn-select").chosen().change(function(){
alert('here');
$("#rack > option").remove();
var id_lantai = $("#id_lantai").val();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>power/get_rack_perlantai"+id_lantai,
success: function(rack){
$.each(rack,function(id_rack,nama_rack){
var opt = $('<option />');
opt.val(id_rack);
opt.text(nama_rack);
$('#rack').append(opt);
});
}
})
});
</script>
<tr><td>FLOOR *</td><td>:</td>
<td>
<select data-placeholder="Floor" class="chzn-select" style="width:200px;" tabindex="2" id="id_lantai" class="required" name="id_lantai" >
<option value="" val_nm_prd="">-SELECT FLOOR -</option>
<?php
foreach($id_lantai as $u){
if($u['id_lantai']==$val){
$selected="selected";
}else{
$selected="";
}
?>
<option value="<?=$u['id_lantai']?>" <?=$selected?> ><?=$u['lantai']?></option>
<?php } ?>
</select>
</td>
</tr>
<tr><td>RACK *</td><td>:</td>
<td>
<select data-placeholder="Rack" class="chzn-select" style="width:200px;" tabindex="2" id="id_rack" class="required" name="id_rack" >
<option value="" val_nm_prd="">-SELECT RACK -</option>
<?php
foreach($id_rack as $u){
if($u['id_lantai']==$vall()){
$selected="selected";
}else{
$selected="";
}
?>
<option value="<?=$u['id_rack']?>" <?=$selected?> ><?=$u['nama_rack']?></option>
<?php } ?>
</select>
</td>
</tr>
//MY CONTROLLERS
function get_rack_perlantai($idlantai)
{
header('Content-Type: application/x-json; charset=utf-8');
echo(json_encode($this->power_model->get_rack($idlantai)));
}
//MY MODELS
function get_lantai() {
$this->db->select('id_lantai, lantai');
$query = $this->db->get('xl_lantai_server');
$lantaivariabel = array();
if ($query -> result()) {
foreach ($query->result() as $lantaix) {
$lantaivariabel[$lantaix -> id_lantai] = $lantaix -> lantai;
}
return $lantaivariabel;
}
else
{
return FALSE;
}
}
//Query untuk ajak lantai & rack
function get_rack($idlantai = null)
{
$this->db->select('id_rack, nama_rack');
if($idlantai != NULL){
$this->db->where('id_lantai', $idlantai);
}
$query = $this->db->get('xl_rack');
$xl_rack = array();
if($query->result()){
foreach ($query->result() as $rack) {
$xl_rack[$rack->id_rack] = $rack->nama_rack;
}
return $xl_rack;
}
else
{
return FALSE;
}
}
sorry my english not good,.:)