javascript - CodeIgniter - Create dynamic html table using form helper functions? -
i've dynamic table adds more rows. here table.
<table> <thead> <tr class="success"> <th>bank/lender</th> <th>add more</th> </tr> </thead> <tbody > <tr> <td> <?php $data = array( 'name' => 'debt_info_bank_name[]', 'id' => '', 'class' => 'form-control', 'placeholder' => 'bank/lender name' ); echo form_input($data); ?> </td> <td> <input class="add btn btn-success btn-sm" type="button" value="add more" /> </td> </tr> </tbody>
and here javascript part:
$(document).on('click','.add',function(){ $(this).val('delete'); $(this).attr('class','del btn btn-danger btn-sm'); var appendtxt = '<tr><td><?php $data = array( 'name' => 'debt_info_bank_name[]', 'id' => '', 'class' => 'form-control', 'placeholder' => 'bank / lender name' ); echo json_encode(form_input($data)); ?></td><td><input class="add btn btn-success btn-sm" type="button" value="add more" /></td></tr>'; $("#dyn_table > tbody > tr:last").after(appendtxt); }); $(document).on('click','.del',function(){ $(this).parent().parent().remove(); });
it adds rows quotes"" in each td element. how can correct it?
note: if add fields in javascript code using html elements like
var appendtxt = '<tr><td><input type="text" placeholder="bank/lender name" /></td> <td><input class="add btn btn-success btn-sm" type="button" value="add more" /></td></tr>';
then goes fine want add fields in codeigniter style
because more safe that.
remove json_encode here. echo
echo form_input($data); ?></td><td><input class="add btn btn-success btn-sm" type="button" value="add more" /></td></tr>';
Comments
Post a Comment