php - JQuery autocomplete and form population using JSON -


I'm having trouble implementing JQuery autocomplete using JSON. Actually, Get a JSON encoded data (I use the codeigniter php structure). JSON format is as follows: [{"id": "1", "Prodname": "candy", "code": "CDD 101", "

Anam ":" Village "," PCNA ":" Sweets "}, {...}}, therefore, part (on the red rectangle on the image) on the Product (Prodamage) field goes.

These are my input fields:

  & lt; Input type = "text" name = "id" value = "" id = "id" size = "3" /> & Lt; Input type = "text" name = "code" value = "" id = "code" size = "5" /> & Lt; Input type = "text" name = "prodname" value = "id =" prodname "size =" 30 "/> & Lt; Input type = "text" name = "range" value = "" id = "range" /> & Lt; / Td> & Lt; Input type = "text" name = "volume" value = "id =" volume "size =" 3 "/> & Lt; Input type = "text" name = "uom" value = "" id = "uom" size = "5" /> & Lt; Button name = "add" type = "button" & gt; Add & lt; / Button & gt;  

Enter image details here < P> Solution:

  $ Ajax ({dataType: 'json', async: false, success: jobs (data) {projects = data;}, url: '& lt ;? php echo site_url (' product / autocomplete / not ') ;; Gt; '}); // Autocomplete $ ("#prodname"). Autocomplete ($ {Source: Projects, Focus: Function (Event, UI) {$ ("#prodname") .val (ui.item.prodname); Return Return;}, Select: Function (Event, UI) {$ (" #prodname ") .val (ui.item.prodname); $ (" #id ") .val (ui.item.id); $ (" #code ") Val (ui.item.code); $ (" #category ") .val (ui.item.pcname); $ (" #uom ") .val (ui.item.uname); return false;}}). Data ("autocomplete") ._Render item = function (ul, item) {return $ ("
  • "). Data ("item.autocomplete", item ) .append ("& lt; a & gt;" + Item.prodname + "& lt; / a & gt;") .appendTo (UL); };

    Does this example help you?

  • Comments