Note that there are some explanatory texts on larger screens.

plurals
  1. POHide not matching options in a search function using jQuery
    text
    copied!<p>I have this search function for a multiple select:</p> <pre><code>var SWAPLIST = {}; SWAPLIST.search = function(list, search) { $(list) .children() .prop('selected', false) .filter(function() { if (!search) { return false; } return $(this) .text() .toLowerCase() .indexOf(search.toLowerCase()) &gt; - 1; }) .prop('selected', true) }; </code></pre> <p>Bound it to this event:</p> <pre><code>$(document).ready(function(){ $('.entitySearch').keyup(function() { var kind = $(this).attr('kind'); var left = '.leftEntities[kind=' + kind +']'; var right = '.rightEntities[kind='+ kind +']'; SWAPLIST.search(left + "," + right, $(this).val()); }); }); </code></pre> <p>This is an example of my multiselect:</p> <pre><code>&lt;select class="leftEntities grid5" kind="&lt;?php echo $firstKeyLeft;?&gt;" multiple="multiple" size="10"&gt; &lt;option&gt; a &lt;/option&gt; &lt;option&gt; ab &lt;/option&gt; &lt;option&gt; abc &lt;/option&gt; &lt;option&gt; abcd &lt;/option&gt; &lt;/select&gt; </code></pre> <p>This is my search input:</p> <pre><code>&lt;div class="grid6 marginTop10px"&gt; &lt;input kind="&lt;?php echo $firstKeyLeft;?&gt;" class="entitySearch form-control-static" role="form" type="text" size="25"/&gt; &lt;span class="glyphicon glyphicon-search"&gt;&lt;/span&gt; &lt;label&gt; Suchen &lt;/label&gt; &lt;/div&gt; </code></pre> <p>And now I want to hide the options that don't match when I'm typing in the search key and of course unhide them when I remove or edit (so that it will match) the typed in search key.</p> <p>Here the original relevant php and html code: <a href="http://codepad.org/4CXgkiei" rel="nofollow">http://codepad.org/4CXgkiei</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload