How can I change this script which right now showing me the code or the name when is equal to the code or name I suggest in the input?
I need that instead of showing me the name the javascript added it automatically
Here are two images:
Here the code :
//autocomplete script
$(document).on('focus','.autocomplete_txt',function(){
type = $(this).data('type');
if(type =='cod' )autoTypeNo=0;
if(type =='nombreProd' )autoTypeNo=1;
$(this).autocomplete({
source: function( request, response ) {
$.ajax({
url : 'include/ajax.php',
dataType: "json",
method: 'post',
data: {
name_startsWith: request.term,
type: type
},
beforeSend: function(){
$('#msgCod').html('<img src="images/ajax-loader.gif"/> verificando');
},
success: function( data ) {
if(data == '') {
$('#submit').attr("disabled", true);
$('#msgCod').html("<div class='alert alert-danger alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>Este producto no existe en la base</div>");
} else if(data != '') {
$('#submit').attr("disabled", false);
$('#msgCod').html("");
}
response( $.map( data, function( item ) {
var code = item.split("|");
return {
label: code[autoTypeNo],
value: code[autoTypeNo],
data : item
}
}));
}
});
},
autoFocus: true,
minLength: 0,
select: function( event, ui ) {
var names = ui.item.data.split("|");
id_arr = $(this).attr('id');
id = id_arr.split("_");
$('#cod_'+id[1]).val(names[0]);
$('#nombreProd_'+id[1]).val(names[1]);
$('#proveedor_'+id[1]).val(names[2]);
$('#maskedDate_'+id[1]).val(names[3]);
$('#venta_'+id[1]).val(names[4]);
$('#existencia_'+id[1]).val(names[5]);
calculateTotal();
}
});
});