JSFiddle - React, Tailwind, and code Playground

by Edgar Martinez

HTML

<onput type='text' id='campoServIsumo'/>

JavaScript

$("#campoServIsumo").autocomplete(
	{  
		source: function(request, response) 
		{
            	$.ajax(
				{
		                  url: "autocomplete/auto_servinsumos.php",
		                  data: 
					{ 
						term: $("#campoServIsumo").val(),
						tipo: $("#SelTipoCot").val(),
						empresa: $("#SelEmpresas").val()
					},
		                  dataType: "json",
		                  type: "GET",
					beforeSend: function()
					{ 
					},
					statusCode: 
					{
						404: function(){ alert("Error al buscar la pagina"); },
						500: function(){ alert("Error en el Servidor, Intente mas tarde");}
					},
		                  success: function(data)
					{
						response(data);
						
					}
	                  });
		},
		minLength: 1,
		select: function(event, ui) 
		{
			$("#campoServIsumo").val(ui.item.value);
		},
		focus: function(event, ui) 
		{ 
			$("#campoServIsumo").val(ui.item.value);
			$("#campoServInsumoID").val(ui.item.id);
		},
		change: function( event, ui ) 
		{ 
		
			if ( !ui.item ) 
			{
         if($("#SelTipoCot").val()==1){
			     $("#campoServIsumo").val('');
			   }
			}
			
		},
		error: function(jqXHR, textStatus, errorThrown)
		{
			alert(jqXHR+' '+textStatus+' '+errorThrown);
		}
	
	});