title: Javascript Product Search (working, but need to filter by search term)
body: <p>I have a little product search code that I've been working on for a while. It works great, although a bit backwards.</p>
  
  <p>The more keywords I type in, ideally, the less products will show up (because it narrows down the results). But as is stands, the more keywords I type in my search system, the MORE products are displayed, because it looks for any product with any of the keywords.
  I want to change the script so that it <em><strong>only shows results if they include ALL the searched for keywords, not ANY of them...</strong></em></p>
  
  <p>Sorry for the long-winded explanation.</p>
  
  <p><strong>Here's the meat and potatoes (jsfiddle):</strong></p>
  
  <p><a href="http://jsfiddle.net/yk0Lhneg/" rel="nofollow">http://jsfiddle.net/yk0Lhneg/</a></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="text" id="edit_search" onkeyup="find_my_div();"&gt;
  &lt;input type="button" onClick="find_my_div();" value="Find"&gt;
  &lt;div id="product_0" class="name" style="display:none"&gt;Mac
      &lt;br/&gt;Apple
      &lt;br/&gt;
      &lt;br/&gt;
  &lt;/div&gt;
  &lt;div id="product_1" class="name" style="display:none"&gt;PC
      &lt;br/&gt;Windows
      &lt;br/&gt;
      &lt;br/&gt;
  &lt;/div&gt;
  &lt;div id="product_2" class="name" style="display:none"&gt;Hybrid
      &lt;br/&gt;Mac PC Apple Windows
      &lt;br/&gt;
      &lt;br/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JAVASCRIPT:</p>
  
  <pre><code>function gid(a_id) {
      return document.getElementById(a_id);
  }
  
  function close_all() {
  
      for (i = 0; i &lt; 999; i++) {
          var o = gid("product_" + i);
          if (o) {
              o.style.display = "none";
          }
      }
  
  }
  
  
  function find_my_div() {
      close_all();
  
      var o_edit = gid("edit_search");
      var str_needle = edit_search.value;
      str_needle = str_needle.toUpperCase();
      var searchStrings = str_needle.split(/\W/);
  
      for (var i = 0, len = searchStrings.length; i &lt; len; i++) {
          var currentSearch = searchStrings[i].toUpperCase();
          if (currentSearch !== "") {
              nameDivs = document.getElementsByClassName("name");
              for (var j = 0, divsLen = nameDivs.length; j &lt; divsLen; j++) {
                  if (nameDivs[j].textContent.toUpperCase().indexOf(currentSearch) !== -1) {
                      nameDivs[j].style.display = "block";
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>So, when you search "mac pc" the only result that should be displayed is the hybrid, because it has both of those keywords. Not all 3 products.</p>
  
  <p>Thank you in advance!</p>