0

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:

show me the item to be selected

selected already by clic

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();


        }                  
    });
});
user3236149
  • 167
  • 4
  • 16
  • What are you trying to do? Please clarify. – Scott Marcus Mar 06 '18 at 16:59
  • Right now show me when I type the code, I need that instead of showing the item the javascript added. When I add the code or the barcode catch the code automatically add it into the inputs in the form – user3236149 Mar 06 '18 at 17:03
  • Possible duplicate of [jquery autocomplete auto fill field with 1st value and highligh added part](https://stackoverflow.com/questions/14062765/jquery-autocomplete-auto-fill-field-with-1st-value-and-highligh-added-part) – Ghassan Elias Mar 06 '18 at 17:43
  • Possible duplicate....jajjaja are you at least saw and read that question?? the code is totally different... but i will tried his solution, maybe works in my code – user3236149 Mar 06 '18 at 19:30

0 Answers0