Note that there are some explanatory texts on larger screens.

plurals
  1. POwhen no checkboxes are selected show a message
    primarykey
    data
    text
    <p>I have a list of store names with check boxes attached. I have another list of taxonomies that belong to these stores. When I click on a store it only shows me the taxonomies that have the same value.</p> <p>I used this script to do that:</p> <pre><code>$(document).ready(function () { $(".store_checkbox").change(function () { $('div[store_id=' + this.value + ']').toggle(this.checked); }).change(); }); </code></pre> <p>Now I want to show a message under my taxonomies <strong>if no boxes are selected</strong></p> <p>How might do this?</p> <p>I tried:</p> <pre><code>$(document).ready(function () { if($('.store_checkbox').find('input[type=checkbox]:checked').length &gt; 0) { $("#hidden_taxon_message").show(); // any one is checked } else { $("#hidden_taxon_message").hide(); // none is checked } }); </code></pre> <p>but it just hides the message regardless if there are checked or unchecked boxes</p> <p>I also tried this :</p> <pre><code>$(function () { if($('.store_checkbox').not(':checked')){ alert("no check boxes"); } }); </code></pre> <p><strong>Updated script all together</strong></p> <pre><code>$(document).ready(function () { $(".store_checkbox").change(function () { $('div[store_id=' + this.value + ']').toggle(this.checked); }).change(); if(!$('.store_checkbox').is(':checked')){ $("#hidden_taxon_message").show(); // any one is checked } else { $("#hidden_taxon_message").hide(); // none is checked } }); </code></pre> <p><strong>Latest Update</strong></p> <pre><code>$(document).ready(function () { $(".store_checkbox").change(function () { $('div[store_id=' + this.value + ']').toggle(this.checked); }).change(); checkIfChecked(); }); $('.store_checkbox').on('change', function () { checkIfChecked(); }); function checkIfChecked() { if ($('.store_checkbox:checked').length == 0) { $("#hidden_taxon_message").show(); // none are checked } else { $("#hidden_taxon_message").hide(); // something is selected } } </code></pre> <p>this is what my js file looks like. the message doesnt seem <strong>TO HIDE</strong>. am I putting it in right?</p> <p><strong>Mark Up</strong></p> <pre><code> &lt;h3&gt;Stores Offered In&lt;/h3&gt; &lt;ul class="multi-column-checkbox"&gt; &lt;% for store in Store.all %&gt; &lt;li&gt;&lt;%= check_box_tag "idea[store_ids][]", store.id, @idea.stores.include?(store), :class =&gt; "store_checkbox" %&gt; &lt;%= store.name %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;br /&gt; &lt;hr /&gt; &lt;h3&gt;Taxonomies Offered In&lt;/h3&gt; &lt;% for store in Store.all %&gt; &lt;% if store.has_taxonomies? %&gt; &lt;div store_id='&lt;%= store.id %&gt;'&gt; &lt;h4&gt;&lt;%= store.name %&gt;&lt;/h4&gt; &lt;ul class="multi-column-checkbox"&gt; &lt;% for taxonomy in store.taxonomies %&gt; &lt;li&gt;&lt;%= check_box_tag "idea[taxonomy_ids][]", taxonomy.id, @idea.taxonomies.include?(taxonomy) %&gt; &lt;%= taxonomy.name %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;div id="hidden_taxon_message"&gt; no checkboxes are selected &lt;/div&gt; </code></pre>
    singulars
    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.
 

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