Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display search results onkeyup?
    primarykey
    data
    text
    <p>I have a search box that as the user types letters into the search box, we will filter and display the results. However, as the user types each letter the search results are getting toggled between showing and hiding. I am very new to JS so I hope it could be an easy fix.</p> <p>Here is my HTML:</p> <pre><code>See Below </code></pre> <p>Here is my toggle JS:</p> <pre><code>See Below </code></pre> <p>How can I tweak the JS to not toggle back and forth?</p> <p>//Here are my edits to help answer the question. This is the JS and HTML I am using to display the results:</p> <p>HTML:</p> <pre><code>&lt;div class="friendssearch" onclick="toggle_visibility('friendslist');"&gt; &lt;div class="friendssearch"&gt; &lt;div id="friendssearchbox"&gt;&lt;/div&gt; &lt;/div&gt; &lt;ul id="friendslist" style="display: none;"&gt; &lt;li&gt; &lt;a href="#"&gt; &lt;div class="friendsflybox" title="Friends Name"&gt; &lt;p class="friendsflyboxname"&gt;Ryan Bennett&lt;/p&gt; &lt;/div&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Javascript:</p> <pre><code>&lt;script&gt; (function ($) { // custom css expression for a case-insensitive contains() jQuery.expr[':'].Contains = function(a,i,m){ return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())&gt;=0; }; function listFilter(header, list) { // header is any element, list is an unordered list // create and add the filter form to the header var form = $("&lt;form&gt;").attr({"class":"filterform","action":"#"}), input = $("&lt;input&gt;").attr({"class":"filterinput clearFieldBlurred ClearField","type":"text", "value":"Start typing a Name"}); $(form).append(input).appendTo(header); $(document).ready(function() { $('.clearField').clearField(); }); $(input) .change( function () { var filter = $(this).val(); if(filter) { // this finds all links in a list that contain the input, // and hide the ones not containing the input while showing the ones that do $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp(); $(list).find("a:Contains(" + filter + ")").parent().slideDown(); } else { $(list).find("li").slideDown(); } return false; }) .keyup( function () { // fire the above change event after every letter $(this).change(); }); } //ondomready $(function () { listFilter($("#friendssearchbox"), $("#friendslist")); }); }(jQuery)); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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