javascript - Filter/Search AND select List -


the requirement complete script able filter/search , select categories of list items. selection must have priority , clear search input.

here code:

    <script> function myfunction() {     var input, filter, ul, li, a, i;      input = document.getelementbyid('myinput');      filter = input.value.touppercase();      ul = document.queryselectorall(".myul");      for(j=0;j< ul.length;j++){           li = ul[j].getelementsbytagname("li");          show = false;          (i = 0; < li.length; i++) {              if (li[i].innerhtml.touppercase().indexof(filter) >= 0) {                  li[i].style.display = "";                 show = true;             } else {                  li[i].style.display = "none";              }          }      }  } </script>      <h1>search</h1> <input type="text" id="myinput" onkeyup="myfunction()" placeholder="search.." title="search keywords">  <p>     <h1>select</h1> <a href="" onclick="myfunction()">hefner</a> <a href="" onclick="myfunction()">syring</a> <a href="" onclick="myfunction()">mccarthy</a> </p>      <h1>results</h1> <ul class="myul"> <li>lavonne hefner</li> <li>lavonne syring</li> <li>marcell syring</li> <li>marcell hefner</li> <li>iona mccarthy</li> <li>iona hefner</li> </ul> 

add parameter:

<a href="" onclick="changefilter('hefner')">hefner</a> 

then add corresponding function:

 function changefilter(value){   myinput.value = value; // set filter   myfunction(); //update results } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -