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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化