douxian9706 2014-09-09 05:19
浏览 55
已采纳

Codeigniter:在动态文本框/ textarea上生成id

I have a problem generating ID's on my dynamic textareas.

Here is my model:

public function select_fields3($tablename3){
     $this->load->library('table');
     $fields = $this->db->field_data($tablename3['table1']);
     return $fields;
 }

Here is my controller:

 public function add_all_inventory(){
    $this->data['title'] = "Add New Inventory";
    $this->load->vars($this->data);
    $table_naming_1 = $_POST['table1'];
    $this->load->view('homeview');

    $select_inv['inventorytype'] = $this->inventory_model->select_tables();
    $this->load->view('inventoryview', $select_inv);

    $select_fields['add_all'] = $this->inventory_model->select_fields3($this->input->post());

    $values_array1 = array('add_all_1' => $select_fields['add_all'],
                           'tablename1' => $table_naming_1);

    $this->load->view('add_all_inventory', $values_array1);

    $this->load->view('footer_view');
}

No need to focus on $select_inv, it's just a reference so I can get the fields of the table loaded. And here is my view:

<div class="row">
<fieldset>
    <form action="" method="POST" id="frm_add_all_inventory" name="frm_add_all_inventory">
    <legend>Add New <input style="border: none; background-color: transparent;" type="text" name="txt_table" id="txt_table" value="<?php echo $tablename1; ?>" readonly/></legend>
            <table style="">
                <?php foreach($add_all_1 as $row) { ?>
                <tr style="">
                    <td style=" height: 50px; width: 100px;font-size: 10pt;"><input style="border: none; background-color: transparent; width: 100%;" type="text" value="<?php echo $row->name; ?>:" readonly/></td>
                    <td style=" height: 50px; width: 200px;"><textarea style="resize: none; font-size: 10pt; width: 100%;"></textarea></td>
                </tr>
                <?php } ?>
                <tr>
                    <td></td>
                    <td></td>
                    <td>
                        <button type="button" class="btn_add_all_inventory btn-success btn-sm"><span class="glyphicon glyphicon-ok"></span>&nbsp;Save</button>
                        <button type="button" class="btn_cancel_all_inventory btn-danger btn-sm"><span class="glyphicon glyphicon-remove"></span>&nbsp;Cancel</button>
                        <button type="button" class="btn_clear_all_inventory btn-warning btn-sm" onclick="document.getElementById('frm_add_all_inventory').reset();"><span class="glyphicon glyphicon-refresh"></span>&nbsp;Clear</button>
                    </td>
                </tr>
             </table>
        </form>
</fieldset>

You see my textarea tag is inside the foreach loop, I wonder how can I generate an ID on my textarea on this one. Hope you could help me. Thank you in advance!

  • 写回答

1条回答 默认 最新

  • duangekui7451 2014-09-09 05:44
    关注

    Can you try it?

    Is this you are trying for?

    <?php
        $count=0; /* Initialize variable */
        foreach($add_all_1 as $row) {
    ?>
          <tr style="">
           <td style=" height: 50px; width: 100px;font-size: 10pt;"><input style="border: none; background-color: transparent; width: 100%;" type="text" value="<?php echo $row->name; ?>:" readonly/></td>
            <td style=" height: 50px; width: 200px;"><textarea style="resize: none; font-size: 10pt; width: 100%;"></textarea></td>
           </tr>
    <?php 
         echo 'Generated Id: ID'.$count; /*Something Prefix*/
         $count=$count+1; /*Increase the Variable*/
        } 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办