AutoComplete to fill in multiple fields?

AutoComplete to fill in multiple fields?

orkneywillorkneywill Posts: 3Questions: 2Answers: 0

Hi all,

I've somehow manage to get this far with my very limited knowledge but can't work out how to complete the last feature I need. In my Editor I've used the autocomplete plugin and it's working as planned to get the product codes:

autoComplete

I've set my JSON response to send back the product code, description and price - but I'm unsure how to access the JSON to use the response for autofilling multiple fields? eg, Description in the description field, price in the price field.

I can set up a full demo if required, currently it's part of a bigger system though so would take a bit of work. Hoping someone can just set me off on the right track if I show how it's currently setup:-

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        "ajax": "php/table.order_inventory.php?o=<?php echo $order_number; ?>&u=<?php echo $userid; ?>",
        "table": "#order_inventory",
        "fields": [
            {
                "label": "Item Number",
                "name": "item_no",
                "type": "autoComplete",
                "opts": { 
                   source: "search.php",
                    minLength: 2
                 }
            },
            {
                "label": "Sell Price",
                "name": "sell_price"
            },

search.php

<?php
sleep( 1 );
// no term passed - just exit early with no response
if (empty($_GET['term'])) exit ;

//connect to database
include("master_config.php");

//retrieve the search term that autocomplete sends
$term = trim(strip_tags($_GET['term']));

$qstring = "SELECT ITM_NO as value, ITM_SHORTDES as description, ITM_WEBSELLmn as sell_price FROM ITM_EXT WHERE ITM_NO LIKE '".$term."%' ORDER BY ITM_NO ASC LIMIT 5";
$result = mysql_query($qstring); //query the database for entries containing the term

while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values
{
        $row['value']=stripslashes($row['value']);
        $row['description']=stripslashes($row['description']);
        $row['sell_price']=stripslashes($row['sell_price']);
        $row_set[] = $row; // build an array
}
$json_str = json_encode($row_set); // format the array into json data
echo $json_str;

Many Thanks,
Will

This discussion has been closed.