I have been banging my head against the wall for hours on this, and I can't seem to figure it out. I have a php file that gets data from a table and converts it into json and displays it like so:
{"id":1,"name":"GR Gas","number":"1","gas":"0.02500000","diesel":"0.03500000"}
I have the jQuery UI Autocomplete plugin on another php web page that has this jQuery written:
$(function () {
$("#customers").autocomplete({
source: "../assets/json_clients.php",
dataType: 'json',
minLength: 2,
select: function (event, ui) {
$("customer-id").val(ui.item.number);
}
});
});
So far it does it's job, it reads the json, and creates the autocomplete drop down under the textbox and i can click on the item. However it is displaying everything in that dropdown that the json outputs, for example it has GR Gas, 1, etc. I only want it do display the "name". When it is clicked it sets the values of hidden text boxes, can someone point me in the right direction?
Thank you in advance for your help!
EDIT Here is the PHP that creates the json:
<?php
header('Content-Type: application/json');
require 'class_dbconnection.php';
$sql = 'SELECT id,c_name,c_number,price_gas,price_distillate FROM mb_clients';
foreach ($Conn->query($sql) as $row) {
$result = array('id' => $row['id'], 'name' => $row['c_name'], 'number' => $row['c_number'], 'gas' => $row['price_gas'], 'diesel' => $row['price_distillate']);
echo json_encode($result, JSON_FORCE_OBJECT);
}
$("customer-id").val(ui.item.number);