1

I am using the jquery autocomplete with php/mysql . I want to retrieve 3 values from the database on autocomplete.

$("#shipper_name").autocomplete({
    source: base_url + 'rainbowsoft/config/functions.php?shipper=shipper',
    focus: function(event, ui) {
        $("#shipper_name").val(ui.item.label);
        return false;
    },
    select: function(event, ui) {
        $("#shipper_name").val(ui.item.label);
        $("#shipper_details").val(ui.item.value);
        $("#client_id_shipper").val(ui.item.id);
        return false;
    }
});

Field with id - client_id_shipper is a hidden field which needs to store an id that is retrieved. My php/mysql returns:

$data[] = array(
   'id'=>$row['id'],
   'label' => $row['client_name'],
   'value'=>$row['client_details'],
);
echo json_encode($data); 

label and value are being displayed properly.SOme issue with the id.

mishik
  • 9,973
  • 9
  • 45
  • 67
user1411837
  • 1,494
  • 6
  • 27
  • 41
  • are you getting the `$row['id']` at server side? – mrsrinivas Jul 02 '13 at 12:29
  • yes i am getting it in json encoded format. – user1411837 Jul 02 '13 at 12:29
  • [{"label":"siddharth","value":"test test test test test test test test test test test test test test test test test test test test ","id":"1"}] – user1411837 Jul 02 '13 at 12:32
  • yes..it is a hidden field in the form,with id='client_id_shipper' – user1411837 Jul 02 '13 at 12:35
  • Is the SQL returning 3 entries? is it returning more and your PHP is filtering it? please provide more information – Noam Rathaus Jul 02 '13 at 12:52
  • yes msqyl returns all 3 fields...i am not getting the value in the hidden field.Cant figure out what the issue is. – user1411837 Jul 02 '13 at 13:05
  • nobody is this portal seems to be having a solution to the problem..well thanks a lot anyway – user1411837 Jul 02 '13 at 13:34
  • Have you try `alert(ui.item.id);` ? Have you try to send your id with different name - for example `my_id` - and than use ui.item.my_id. By the way: others have problem with hidden input too - [Set value of hidden field in a form using jQuery's “.val()” doesn't work !](http://stackoverflow.com/questions/2979772/set-value-of-hidden-field-in-a-form-using-jquerys-val-doesnt-work) – furas Jul 02 '13 at 15:03

0 Answers0