【问题标题】:checkbox view data and on change based on dropdown list复选框查看数据并根据下拉列表进行更改
【发布时间】:2017-10-14 15:50:13
【问题描述】:

我想查看复选框作为类别的 id 并取决于下拉选择有人可以帮助我

下拉选择运行良好,但 onchange 不起作用,如果我得到依赖于选择类别的子类别,如何在 mysql 数据库中插入多复选框

' 我的观点是

  echo '<div class="control-group">';
    echo '<label for="category_id" class="control-label">category</label>';
    echo '<div class="controls">';
      //echo form_dropdown('category_id', $options_category, '', 'class="span2"');
      $js = 'id="category_sub" onChange="some_function();"';
      echo form_dropdown('category_id', $options_category, set_value('category_id'), 'class="span2" id="category_id"',$js);

    echo '</div>';
  echo '</div">';

  if( isset($_POST['category_id']) != ''){echo '<div class="control-group" id="category_sub"></div>';
  foreach ($services as $row){ 
$id = $row['ID']      ;   $options_sub_category = $row['Name_En'];

     // echo $options_sub_category ;
     //echo form_checkbox($options_sub_category, $options_sub_category, TRUE, 'class="span2" id="services"');
echo '<input type ="checkbox" name="services" id ="services" value="'. echo $id .'"> '. echo $options_sub_category ; .'';           

 }
  }

我的控制者是

公共函数add() {

if(isset($_POST['category_id']) && $this->input->post('category_id')!=null){
    $id = $this->input->post('category_id');

$data ['services']  = $this->service_model->get_services($id);
}
//if save button was clicked, get the data sent via post

//fetch categorys data to populate the select field
$data['categorys'] = $this->category_model->get_category();


//load the view
$data['main_content'] = 'admin/company/add';
$this->load->view('includes/template', $data);  } 

我的模型是

公共函数 get_services($id) {

$this->db->select('*');

$this->db->where('category_id', $id);
$this->db->from('service');


$query = $this->db->get();

return $query->result_array();  }

【问题讨论】:

  • 从 foreach 获取的值 ($services as $row) { $options_sub_category[$row['ID']] = $row['Name_Ar']; }
  • 请分享完整代码
  • 你在 $options_sub_category 变量中传递了什么?您是否在 $options_sub_category 中传递数组?
  • 是的,传递数组

标签: php codeigniter


【解决方案1】:

下拉列表是一个列表框,可以取多个值。

echo form_dropdown('category_id', $options_category, '', 'class="span2"');

创建一个包含多个列表值的下拉列表。

form_checkbox() 

一次创建一个复选框。所以不要使用 $options_sub_category 数组,而是在函数中使用它的值:

echo form_checkbox('services',  $value, TRUE, 'class="span2"');

请将 $value 更改为您的变量名。

【讨论】:

  • 但我想保存多个复选框和它的值相同 foreach ($services as $row) { $options_sub_category[$row['ID']] = $row['Name_Ar']; }
  • 看答案 2 这是我的鳕鱼,你能帮帮我吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-04
  • 2016-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-21
相关资源
最近更新 更多