i'm trying to use Jquery autocomplete function getting data from a multidimensional array (see the code below), i want that user write on the form field called "descrizione" getting results from the array field "prodotto" and automatically when he confirm the product chosen the other fields are set. Anyone can help me to understand what is wrong on the code? Thanks for your kind cooperation!
<script>
$(function() {
var availableDescrizioni = [
{ prodotto: "test test", codice_prodotto: "product_code001", prezzo: "122,22", iva: "22" },
{ prodotto: "nome_prodotto1", codice_prodotto: "cod_produttore1", prezzo: "22,22", iva: "22" }
];
$("#descrizione").autocomplete({
source: $availableDescrizioni,
focus: function(event, ui) {
$("#descrizione").val(ui.item.prodotto);
return false;
},
select: function(event, ui) {
$("#descrizione").val(ui.item.prodotto);
$("#cod_prodotto").val(ui.item.codice_prodotto);
$("#prezzo_unitario").val(ui.item.prezzo);
return false;
}
});
});
</script>
<input type="text" id="cod_prodotto" name="cod_prodotto" class="colonna col_codprodotto"/>
<input type="text" name="quantita" class="colonna col_quantita"/>
<input type="text" id="descrizione" name="descrizione" class="colonna col_descrizione"/>
<input type="text" id="prezzo_unitario" name="prezzo_unitario" class="colonna col_prezzo"/>
<input type="text" name="cod_iva" class="colonna col_prezzo"/>