Welcome Guest, Not a member yet? Register   Sign In
Populating Multiple Select Boxes
#4

[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:
&lt; script type text/js &gt;
// JS Ajax call to update billing or auto incasso
$("#first").change(function(){
    var type = this.val();
    // Then, call Ajax to process request :)
    $.ajax({
        url: "&lt;?php echo base_url();?&gt;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 Smile

Have fun...

Cheers,
Smilie


Messages In This Thread
Populating Multiple Select Boxes - by El Forum - 07-07-2011, 11:36 PM
Populating Multiple Select Boxes - by El Forum - 07-08-2011, 02:02 AM
Populating Multiple Select Boxes - by El Forum - 07-08-2011, 02:05 AM
Populating Multiple Select Boxes - by El Forum - 07-08-2011, 03:03 AM
Populating Multiple Select Boxes - by El Forum - 07-08-2011, 06:58 PM
Populating Multiple Select Boxes - by El Forum - 07-11-2011, 03:56 AM
Populating Multiple Select Boxes - by El Forum - 07-11-2011, 10:30 AM
Populating Multiple Select Boxes - by El Forum - 07-13-2011, 06:01 PM
Populating Multiple Select Boxes - by El Forum - 02-28-2012, 11:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB