2013-12-21 49 views
0

在下面代码我已放置在控制器,型号视图一部分。我的目标是如果我从下拉列表中选择考试名称,它应该提醒所选的exam。我的实际结果是,如果我选择考试名称,它会引发“海”警报味精而不是考试名称。请解决我的问题。所选的值应显示警报MSG

控制器:

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 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(); 
    } 


视图:

<script type="text/javascript" charset="utf-8"> 
function get_subjectcodedetails() { 
alert("hai"); 
     //var course_name = jQuery('#course_name_id').val(); 
     var exam_name = jQuery('#exam_name_id').val(); 

     //alert("course_name"+course_name); 
     alert("exam_name"+exam_name); 
     jQuery.ajax({ 
     data: '&exam_name='+exam_name, 
     type: 'POST', 
     url: 'import/subjectcodedetails', 
     success: function(data){ 
      //alert("inside change"+data); 
      console.log(data); 
      jQuery('#ssubject_code').html(data); 
     } 
    }); 

} 
</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" onChange="get_subjectcodedetails()"'); 
?> 
<div id="ssubject_code"> 

回答

0

尝试这样

<script type="text/javascript" charset="utf-8"> 
function get_subjectcodedetails(obj) {   
    var exam_name = obj.value; // getting value   
    alert("exam_name"+exam_name); 
    jQuery.ajax({ 
    data: 'exam_name='+exam_name, 
    type: 'POST', 
    url: 'import/subjectcodedetails', 
    success: function(data){ 
     //alert("inside change"+data); 
     console.log(data); 
     jQuery('#ssubject_code').html(data); 
    } 
}); 

} 
</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" onChange="get_subjectcodedetails(this)"'); 
?> 
0

可能我建议删除

alert("hai");