简体   繁体   English

Codeigniter根据其他选择选项更新选择选项

[英]Codeigniter update select options based on other select option

So, I am fairly new to codeignitor and was hoping to get some help. 因此,我对Codeignitor还是陌生的,希望能得到一些帮助。 Below I have my controller(Estimates.php), my model(Invoice_items_model.php) and my view(_add_edit_items.php). 下面是控制器(Estimates.php),模型(Invoice_items_model.php)和视图(_add_edit_items.php)。 These are shortened versions as the full versions are pretty long. 这些是简化版,因为完整版相当长。

What I am looking to do is have it so that when one of the select options is clicked it will then check the $suboption['non_compatible'] field for that suboption. 我想要做的是拥有它,以便在单击选择选项之一时,它将检查该子选项的$ suboption ['non_compatible']字段。 If the suboption in any of the other select options matches that non_compatible field it will be disabled. 如果任何其他选择选项中的子选项与该不兼容字段匹配,它将被禁用。

I found this post that I could probably work with but i'm not sure how to do an onchange event for dynamically generated selects. 我找到了可以与我合作的帖子 ,但不确定如何为动态生成的选择执行onchange事件。

Estimates.php Estimates.php

 `public function estimate($id = ''){$data['platforms']         = $this->invoice_items_model->get_platforms();
$data['options']           = $this->invoice_items_model->get_options();
$data['suboptions']        = $this->invoice_items_model->get_suboptions();
$this->load->view('admin/estimates/_add_edit_items', $data);}`

Invoice_items_model.php Invoice_items_model.php

public function get_platforms()
{
    $platforms = array();
    $this->db->order_by('name', 'asc');    

    return $this->db->get('tblplatforms')->result_array();
}
public function get_options()
{
    $options = array();

    return $this->db->get('tblplatform_options')->result_array();
}
public function get_suboptions()
{
    $suboptions = array();

    return $this->db->get('tblplatform_suboptions')->result_array();
}

}' }”

_add_edit_items.php _add_edit_items.php

          <?php foreach($options as $option) { ?>
            <tr>
              <td></td>
              <td><p><?php echo $option['name']; ;?>:</p></td>
              <td>
                <select name="<?php echo $option['name']; ?>" id="<?php echo $option['name']; ?>" rows="4" class="form-control">                     
                  <?php foreach($suboptions as $suboption) { ?>
                    <?php if($suboption['plat_option'] ==  $option['name']) { ?>
                      <option value="<?php echo $suboption['name']; ?>" id="<?php echo $suboption['name']; ?>"><?php echo $suboption['name']; ?></option>
                    <?php } ?>
                  <?php } ?>
                </select>
              </td> 
            </tr>
          <?php } ?>
          <tr>

keep your code as it is just change the event like this. 保留您的代码,因为它只是像这样更改事件。

$(document).on("onChange", "your_selector", function() {
   // your code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM