Welcome Guest, Not a member yet? Register   Sign In
Setting csrf_regenerate as TRUE
#6

Thanks Martin. I am using jquery.

I am giving detailed code here:

Quote:$('#project_id').change(function() {

        var project_id=$("#project_id").val();
        var domain=$("#domain").val();

        $.ajax({
                type: "POST",
                url: domain + "index.php/project/get_department",
                data: {project_id: project_id},
                dataType: 'json',
                success: 
            function(j){              
 
              if(j.length >= 2) {
                var options = '';
                for (var i = 0; i < j.length; i++) {
                        options += '<option value="' + j[i].id + '">' + j[i].name + '</option>';
                }
                $("#department_id").html(options);
                $('#department_id option:first').attr('selected', 'selected');
              }
              else if (j.length == 1){
         
               options += '<option value="' + j[0].id + '">' + '------------------------------------' + '</option>';
                $("#department_id").html(options);
                $('#department_id option:first').attr('selected', 'selected');
              }
              else{
                $("#department_id").val(j[1].id);
              }
              
            }
          });  
  });  

The get_department function is below:

Quote:public function get_department()
    {

        $project_id = $this->input->post('project_id');      
        if(is_numeric($project_id) && $project_id > 0 && $project_id == round($project_id, 0)){

        $sql = "SELECT department.id, department.name FROM project, department,project_dept
        WHERE project.id= ? and project.id= project_dept.project_id and department.id= project_dept.department_id order by            department.name";
        $query = $this->db->query($sql, array($project_id));
        $loop = html_escape($query->result_array());
    
        $r[0] = "----- Select Departments -----";
        foreach ($loop as $row)
        $r[$row['id']] = $row['name'];
 
        $dept = $r;

        $json = '['; 
        $json_names = array();
        foreach ($dept as $id => $name) {
          $json_names[] = '{"id": "'.$id.'", "name": "'.$name.'"}';
        }
        
        $json .= implode(',', $json_names); 
        $json .= ']'; 
        echo $json;     
}
    else
exit();
    }

Now how do I incorporate your json code with this code ?
Reply


Messages In This Thread
Setting csrf_regenerate as TRUE - by june123 - 07-27-2017, 04:45 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-27-2017, 08:27 AM
RE: Setting csrf_regenerate as TRUE - by spjonez - 07-27-2017, 06:21 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-28-2017, 01:36 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-28-2017, 06:15 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-28-2017, 11:50 PM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-31-2017, 12:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB