php - Dependent dropdown is not working using codeigniter

314

In the below codeigniter code i have placed controller,model and view.My aim when i select exam name it should drop corresponding course code from examcourse table.But my actual result when i select exam name it is not droping the dropdown .Pls help me to do this.

Controller:import

public function index()

    {   
//echo "inside form upload";   

        $data = array();
        //$college_name = $this->session->userdata('college_name');
        if($query = $this->import_model->get_exam_data())
        {
            $data['exam_data'] = $query;
        }
        //$this->load->view('student_view', $data);

        $this->load->view('form_upload',$data);
    }
    function subjectcodedetails()
    {   
        $data = array();
        //$college_name = $this->session->userdata('college_name');
        $exam_name = $this->input->post('exam_name');
        //$course_name = $this->input->post('course_name');
        if($query = $this->import_model->get_subject_records($exam_name))
        {
            $data['course_code'] = $query;
        }
        $this->load->view('subject_view', $data);
    }


model:

function get_exam_data()
    {
        $this->db->distinct();
        $this->db->select("CONCAT(exam_name) AS fullexamname", FALSE);//this will concat the value
        //$this->db->where('college_name',$college_name);
        $query = $this->db->get('examcourse');
        return $query->result();
    }
    function get_subject_records($exam_name)
    {
        //echo "exam_name inside get_subject_records".$exam_name;
        $this->db->select('course_code');
        //$this->db->where('exam_name',$exam_name);
        $this->db->where('fullexamname',$exam_name);
        //$this->db->where('college_name',$college_name);
        $query = $this->db->get('examcourse');
        return $query->result();

    }


view: form_upload

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
   <script type="text/javascript">
    $(document).ready(function(){
        $(".dropdown_class").change(function()
        {
            var id=$(this).val();
            // Please find the course_code, course_code was not found
            var dataString = 'course_code='+ id;
            $.ajax
            ({
                type: "POST",
                url: "import/subjectcodedetails",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    $(".dropdown_class12").html(html);
                } 
            });

        });
</script>
<form action="http://localhost/CodeIgniter/index.php/import/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">        <?php 
        $data = array();
        $data["Select Exam Name"] = "Select Exam Name"; 
        foreach ($exam_data as $row)
        {
            $data[$row->fullexamname] = $row->fullexamname; 
        }
        echo form_dropdown('exam_name', $data, 'small', 'class="dropdown_class"  id="exam_name_id" ');
?>


view:subject_view

<?php 
        $data = array();
        foreach ($course_records as $row)
        {
            $data[$row->course_code] = $row->course_code; 
        } 
        echo form_dropdown('course_name', $data, 'small','class="dropdown_class12"  id="course_name_id"');
?>  
212

Answer

Solution:

{-code-1}

Missing} at the end of$(document).ready block

People are also looking for solutions to the problem: php - Strange Curl behaviour while passing variable

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.