Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckboxes filter using jQuery
    primarykey
    data
    text
    <p>I'm trying to make the following code work, but my jQuery skills are so basic, I can't find the problem</p> <p>This code is meant to filter a list based on arrays of checkboxes</p> <p>The code is very probably bug free</p> <p>The problem certainly comes from something stupid like not declaring correctly, not testing in the right conditions or not calling a required script</p> <p>Thanks a million!</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $("#options input.type_check").click(function() { if($(this).is(':checked')) { $("#events li."+$(this).attr('id')).removeClass('type_hidden'); if(!$("#events li."+$(this).attr('id')).hasClass('start_hidden')) { $("#events li).not(".type_hidden, .start_hidden").slideDown(); } } else { $("#events li."+$(this).attr('id')).addClass('type_hidden'); $("#events li."+$(this).attr('id')).slideUp(); } return false; }); $("#options input.start_check").click(function() { if($(this).is(':checked')) { $("#events li."+$(this).attr('id')).removeClass('start_hidden'); if(!$("#events li."+$(this).attr('id')).hasClass('type_hidden')) { $("#events li).not(".type_hidden, .start_hidden").slideDown(); } } else { $("#events li."+$(this).attr('id')).addClass('start_hidden'); $("#events li."+$(this).attr('id')).slideUp(); } return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Types:&lt;/p&gt; &lt;div&gt;&lt;input name="type[]" type="checkbox" id="type_0" value="0" class="type_check" checked="checked" /&gt;&lt;label for="type_0"&gt;Type 0&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="type[]" type="checkbox" id="type_1" value="1" class="type_check" checked="checked" /&gt;&lt;label for="type_1"&gt;Type 1&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="type[]" type="checkbox" id="type_2" value="2" class="type_check" checked="checked" /&gt;&lt;label for="type_2"&gt;Type 2&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="type[]" type="checkbox" id="type_3" value="3" class="type_check" checked="checked" /&gt;&lt;label for="type_3"&gt;Type 3&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="type[]" type="checkbox" id="type_4" value="4" class="type_check" checked="checked" /&gt;&lt;label for="type_4"&gt;Type 4&lt;/label&gt;&lt;/div&gt; &lt;p&gt;Starts:&lt;/p&gt; &lt;div&gt;&lt;input name="start[]" type="checkbox" id="start_072009" value="072009" class="start_check" checked="checked" /&gt;&lt;label for="type_072009"&gt;July 2009&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="start[]" type="checkbox" id="start_082009" value="082009" class="start_check" checked="checked" /&gt;&lt;label for="type_082009"&gt;August 2009&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="start[]" type="checkbox" id="start_092009" value="092009" class="start_check" checked="checked" /&gt;&lt;label for="type_092009"&gt;September 2009&lt;/label&gt;&lt;/div&gt; &lt;div&gt;&lt;input name="start[]" type="checkbox" id="start_102009" value="102009" class="start_check" checked="checked" /&gt;&lt;label for="type_102009"&gt;October 2009&lt;/label&gt;&lt;/div&gt; &lt;p&gt;Events&lt;/p&gt; &lt;ul id="events"&gt; &lt;li id="a1768" class="type_0 start_072009"&gt;Event 1&lt;/li&gt; &lt;li id="a2190" class="type_1 start_072009"&gt;Event 2&lt;/li&gt; &lt;li id="a2191" class="type_2 start_072009"&gt;Event 3&lt;/li&gt; &lt;li id="a1864" class="type_2 start_082009"&gt;Event 4&lt;/li&gt; &lt;li id="a1679" class="type_3 start_082009"&gt;Event 5&lt;/li&gt; &lt;li id="a2042" class="type_0 start_092009"&gt;Event 6&lt;/li&gt; &lt;li id="a1717" class="type_4 start_092009"&gt;Event 7&lt;/li&gt; &lt;li id="a1917" class="type_4 start_092009"&gt;Event 8&lt;/li&gt; &lt;li id="a1767" class="type_4 start_092009"&gt;Event 9&lt;/li&gt; &lt;li id="a1866" class="type_2 start_102009"&gt;Event 10&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&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.
 

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