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

时间:2014-09-09 05:19:17

标签: javascript php jquery html codeigniter

我在动态textareas上生成ID时遇到问题。

这是我的模特:

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

这是我的控制器:

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

无需专注于$ select_inv,它只是一个参考,所以我可以加载表的字段。这是我的观点:

<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>

你看到我的textarea标签在foreach循环中,我想知道如何在我的textarea上生成一个ID。希望你能帮助我。提前谢谢!

1 个答案:

答案 0 :(得分:1)

你能试试吗?

这是你在尝试吗?

<?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*/
    } 
?>