Note that there are some explanatory texts on larger screens.

plurals
  1. POToggle hiding certain values in a dropdown box using a checkbox and jQuery
    primarykey
    data
    text
    <p>I have a drop down box filled with options pulled from a database. Each of these options will have an active indicator value of either 'Y' or 'N'. I have a checkbox which will include all options or just the active ones.</p> <p>I currently have the options pulling from the database perfectly. The for loop that inputs the options looks like this: </p> <pre><code>for ($i = 0; $i &lt; count($category_record); $i++) { if($category_record[$i]-&gt;getActiveInd() == "Y") { echo '&lt;option value="'.$category_record[$i]-&gt;getId().'" '.$checked.' &gt;&amp;nbsp;&amp;nbsp; - '.$category_record[$i]-&gt;getTitle().'&lt;/option&gt;'; } else if($category_record[$i]-&gt;getActiveInd() == "N") { echo '&lt;option id="inactive" value="'.$category_record[$i]-&gt;getId().'" '.$checked.' &gt;&amp;nbsp;&amp;nbsp; - '.$category_record[$i]-&gt;getTitle().'&lt;/option&gt;'; } </code></pre> <p>So if the value is an inactive value, that option will have an id of '#inactive'.</p> <p>The checkbox is a simple one:</p> <pre><code>&lt;input type="checkbox" name="search_active" id="checkbox" /&gt; </code></pre> <p>The jQuery I have at the moment looks like this:</p> <pre><code>$(document).ready(function() { $('input[type=checkbox]').click(function(){ var $this = $(this); if($this.is(':checked')) { $('#inactive').show(); } else { $('#inactive').hide(); } }); }); </code></pre> <p>This code does work, slightly, in that it will hide inactive values when the checkbox is unticked, however it will only hide the first value it comes across and not all of them. I have inspected the elements and they all still definitely have the #inactive id but they won't hide. I have searched for an answer but haven't been able to find one, what am I doing wrong?</p>
    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