• User

    Autocomplete cerca su 2 campi del db

    Salve ho questo script,
    ora l'autocomplete lo fa sul CODE, vorrei , lasciando la visualizzazione come ora (CODE ° DESCRIZIONE)
    che faccia anche la ricerca su DESCRIZIONE, come posso fare?
    Grazie

    
    
    <script> function autocomplete(inp, arr) {   var currentFocus;    inp.addEventListener("input", function(e) {      var a, b, i, val = this.value;       closeAllLists();      if (!val) { return false;}      currentFocus = -1;      a = document.createElement("DIV");      a.setAttribute("id", this.id + "autocomplete-list");      a.setAttribute("class", "autocomplete-items");      this.parentNode.appendChild(a);      for (i = 0; i < arr.length; i++) {        if (arr*.substr(0, val.length).toUpperCase() == val.toUpperCase()) {          b = document.createElement("DIV");           b.innerHTML = "<strong>" + arr*.substr(0, val.length) + "</strong>";          b.innerHTML += arr*.substr(val.length);          b.innerHTML += "<input type='hidden' value='" + arr* + "'>";          b.addEventListener("click", function(e) {              inp.value = this.getElementsByTagName("input")[0].value;              closeAllLists();          });          a.appendChild(b);        }      }   });    inp.addEventListener("keydown", function(e) {      var x = document.getElementById(this.id + "autocomplete-list");      if (x) x = x.getElementsByTagName("div");      if (e.keyCode == 40) {         currentFocus++;         addActive(x);      } else if (e.keyCode == 38) {         currentFocus--;         addActive(x);      } else if (e.keyCode == 13) {         e.preventDefault();        if (currentFocus > -1) {           if (x) x[currentFocus].click();        }      }   });   function addActive(x) {    if (!x) return false;     removeActive(x);    if (currentFocus >= x.length) currentFocus = 0;    if (currentFocus < 0) currentFocus = (x.length - 1);    x[currentFocus].classList.add("autocomplete-active");   }   function removeActive(x) {    for (var i = 0; i < x.length; i++) {      x*.classList.remove("autocomplete-active");    }   }   function closeAllLists(elmnt) {    var x = document.getElementsByClassName("autocomplete-items");    for (var i = 0; i < x.length; i++) {      if (elmnt != x* && elmnt != inp) {        x*.parentNode.removeChild(x*);      }    }   }   document.addEventListener("click", function (e) {      closeAllLists(e.target);   }); }  var clifora = [ <%  Set objConn=Server.CreateObject("ADODB.Connection") objConn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=XXXXXXX;DATABASE=XXXXX;UID=XXXXXX;PASSWORD=XXXXX" Set objRs1 = Server.CreateObject("ADODB.Recordset") strSQL1="SELECT Code, Descrizione FROM Prodotti " objRs1.Open strSQL1, objConn While objRs1.EOF = False   vBar = Replace(objrs1("Code"), """", "&quot;") if vBar <> "" then Code = Code&""""&vBar&" °  "&objrs1("Descrizione")&""","  objRs1.Movenext Wend objRs1.close set objRs1 = Nothing  response.Write(left(Code,len(Code)-1))  %>  ];  autocomplete(document.getElementById("Art"), clifora); </script>
    
    

    Grazie