Welcome Guest, Not a member yet? Register   Sign In
Chained DropDownLists
#3

[eluser]jojo777[/eluser]
Sorry i'm not english native but if i'm not wrong you are asking about 2 dependent select list.

I had that problem in a project. It was about Island and City. I finally did it with jQuery/AJAX.

Try this.

Code:
$(document).ready(function(){  
  $("#idselect1").bind('change', function(){
            load_select2();
  });
});

So wen you choose an option in option list number 1 you will launch load_select2(). Its like this.

Code:
function load_select2(callback){
        //alert('hi dude!');
   if($("#idselect1").val()!=""){
    // set the variable
    var dato=$("#idselect1").val();
    //AJAX
    $.ajax({
     type:"POST",
     dataType:"html",
     //i think base_url is not necesary, but only in case you need full path.
     url:base_url+"your_controller/your_load_optionlist_function",
     data:"idselect1="+dato,
     success:function(msg){
      // when the controller's function end it'll load a view with all the options
      $("#idselect2").empty().removeAttr("disabled").append(msg);
                        callback();
     }
    });
   }else{
    $("#idselect2").empty().attr("disabled","disabled");
   }
    }

And in your controller

Code:
function your_load_optionlist_function()
        {
            $id1 = $this->input->post('idselect1');
            $data['results'] = your_model->your_query($id1);
            $this->load->view("myview/select_list_2",$data);
     }

So your view is simple foreach inside an option tag...
Code:
<option value="-1">SELECT</option>
&lt;?php
foreach($results as $row)
{
# stuff...
}
?&gt;

Hope it helps dude! Maybe there are other options to do this, but this one worked for me.


Messages In This Thread
Chained DropDownLists - by El Forum - 10-24-2012, 01:11 AM
Chained DropDownLists - by El Forum - 10-24-2012, 04:24 AM
Chained DropDownLists - by El Forum - 10-24-2012, 06:01 AM
Chained DropDownLists - by El Forum - 10-25-2012, 05:05 AM
Chained DropDownLists - by El Forum - 10-25-2012, 05:10 AM
Chained DropDownLists - by El Forum - 10-25-2012, 05:20 AM
Chained DropDownLists - by El Forum - 10-25-2012, 05:35 AM
Chained DropDownLists - by El Forum - 10-25-2012, 05:45 AM
Chained DropDownLists - by El Forum - 10-25-2012, 06:06 AM
Chained DropDownLists - by El Forum - 10-25-2012, 06:13 AM
Chained DropDownLists - by El Forum - 10-25-2012, 07:03 AM
Chained DropDownLists - by El Forum - 10-25-2012, 07:09 AM
Chained DropDownLists - by El Forum - 10-25-2012, 07:14 AM
Chained DropDownLists - by El Forum - 10-25-2012, 07:24 AM
Chained DropDownLists - by El Forum - 10-25-2012, 07:26 AM
Chained DropDownLists - by El Forum - 10-25-2012, 07:45 AM
Chained DropDownLists - by El Forum - 10-25-2012, 09:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB