[eluser]mohssenvox[/eluser]
hi , i am trying to autocomplete textbox , here is my code:
view:
Code:
[removed]
var rowNum = 0;
function addRow(frm) {
rowNum++;
var row = '<tr id="rowNum' + rowNum + '"><td> </td><td><input type="button" value="Remove" + rowNum + ');"></td><td ><input type="text" value="" name="txtObjectName[]" id="txtObjectName" class="txtObjectName" ></td><td><input type="text" name="txtUnitPrice[]" read value=""></td><td><input type="text" name="txtCountObject[]" value=""></td></tr>';
jQuery('#test').append(row);
}
function removeRow(rnum) {
jQuery('#rowNum' + rnum).remove();
}
[removed]
[removed]var site = "<?php echo site_url(); ?>
";
$(function(){
$('.txtObjectName').autocomplete({
serviceUrl: site+'/test/search',
onSelect: function (suggestion) {
$("#txtUnitPrice").val(suggestion.data);
}
});
});
[removed]
?php
$data = array("name" => "txtObjectName[]", "id" => "txtObjectName","class"=>"txtObjectName");
echo form_input($data);
?>
controller:
Code:
public function search() {
$keyword = $this -> uri -> segment(3);
$data = $this -> db -> from('service') -> like('name', $keyword) -> get();
foreach ($data->result() as $row) {
$arr['query'] = $keyword;
$arr['suggestions'][] = array('value' => $row -> name, 'data' => $row -> price);
}
echo json_encode($arr);
}
in normal way , auto complete work fine with php code(first input that created with form helper). but when i add new input with my jquery code , auto complete only work with first input , and dont work with new input , that jquery added on my form...
any idea..?