I've been searching all over, and actually have found some of similar problem, but still can't manage to solve my problem. I'm still struggling learning jquery and still new.
Anywa, I'm trying to add dynamically an input on a table. So far, I've been able to show the adding of row with the new input text. The input text suppose to have autocomplete function. But the new dynamically added input never succeed to show the autocomplete options.
(To make it clear, I put down the code into JSFiddle, here's the link:
http://jsfiddle.net/yodann/6t74T/637/ )
Here is my code:
<?php
echo '<tr class="row_odd"><td class="ui-widget">';
echo form_input(array('id' => 'aff[]', 'name' => 'aff', 'value' => '',
'class' => 'form-control auto_form', 'placeholder' => 'Masukkan nama tempat',
'style' => 'width:100%'));
echo '</td><td><img src="'.getfrontendlink('images/del_button.png').
'" width="24px" height="auto"></td></tr>';
?>
function addRow() {
var count = $('#aff_table tr').length;
var tx = count % 2 == 0 ? 'row_even' : 'row_odd';
$('#aff_table tr:last').after('<tr class="' + tx + '">' +
'<td class="ui-widget">'+
'</td><td><img src="<?=getfrontendlink('images/del_button.png')?>" width="24px" height="auto"></td></tr>');
var dat = $('#aff_table tr:last').children('td.ui-widget');
$("input.auto_form:last").clone(true).appendTo(dat);
$("input.auto_form:last").val("");
}
<?php
if ($datas != '') {
$i = 0;
$php_array = array();
foreach ($datas->result_array() as $row):
$php_array[$i++] = ($row['pp_id'].'>>'.$row['pp_name'].', '.
(strlen($row['address']) > 25 ? substr($row['address'],0,25) : $row['address']).', '.
$row['city_name'].', '.$row['province_name']);
endforeach;
$js_array = json_encode($php_array);
echo "var availableTags = ". $js_array . ";\n";
}
?>
$( ".auto_form" ).autocomplete({
source: availableTags
});