javascript - Search bar works with values typed or clicked by user -


i'm trying have search bar 2 behaviors:

  1. user enters values search bar
  2. user can click on elements several lists

case 1. working fine.

case 2. right now, user needs hit enter validate search. display results value entered input field, user doesn't have hit enter.

any on appreciated. thanks!

below code:

function recherche(){   var search = $('#search').val();   if(search.length < 1) {     return null;   };    var results = json.filter(function (el) {     var s = search.tolowercase().split(" ");     (var key in el) {       (var i=0; < s.length; i++) {         if (el[key].tolowercase().indexof(s[i]) != -1) {           s.splice(i,1);           i--;           if (!s.length) return true;         }       }     }     return false;   });   displaysearchresults(results); };  var items = document.getelementbyid("filter"); var item = items.getelementsbytagname("li"); for(var i=0; i<item.length; i++) {   item[i].addeventlistener("click", function(e) {     console.log(this.textcontent || this.innertext);     document.getelementbyid("search").value = (this.textcontent || this.innertext);   }); }  $(function() {   recherche();   $('#search').keyup(recherche); }); 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -