Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: filtering dropdown still showing the first element after the filtering
    text
    copied!<p>I am trying to filter dropdown options based on the radiobutton selected. The filtering is happening just fine, but the problem is, after the filtering happens, the first element is still being shown. </p> <p>Check the demo: <a href="http://jsfiddle.net/animeshb/7Wqfj/" rel="nofollow">http://jsfiddle.net/animeshb/7Wqfj/</a></p> <pre><code>&lt;div id="step1"&gt; &lt;input class="radiobutton" dataval="PAT" name="TemplateTypes" type="radio" /&gt; &lt;div&gt;Patient&lt;/div&gt; &lt;input class="radiobutton" dataval="EMPLOYEE" name="TemplateTypes" type="radio" /&gt; &lt;div&gt;Employee&lt;/div&gt; &lt;input class="radiobutton" dataval="MACHINE" name="TemplateTypes" type="radio" /&gt; &lt;div&gt;Machine&lt;/div&gt; &lt;select class="selectLDlist" id="ddlAllTemplates" name="AllTemplates"&gt; &lt;option value="77492|ET_07|EMPLOYEE|08/16/13|08/16/14|Approved|Y|70744"&gt;EMPLOYEE&lt;/option&gt; &lt;option value="70470|testing|PAT|08/16/13|08/16/14|Approved|Y|70428"&gt;Patient&lt;/option&gt; &lt;option value="70472|testing|PAT|08/12/13|08/16/14|Approved|Y|30213"&gt;Patient&lt;/option&gt; &lt;option value="70472|testing|EMPLOYEE|08/13/13|08/16/14|Approved|Y|30213"&gt;EMPLOYEE&lt;/option&gt; &lt;option value="70472|testing|PAT|08/14/13|08/16/14|Approved|Y|30213"&gt;Patient&lt;/option&gt; &lt;option value="70472|testing|MACHINE|08/14/13|08/16/14|Approved|Y|30213"&gt;MACHINE&lt;/option&gt; &lt;option value="70472|testing|PAT|08/14/13|08/16/14|Approved|Y|30213"&gt;Patient&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; </code></pre> <p>and the jQuery:</p> <pre><code>$('.radiobutton').change(function () { var templateType = $("#step1 input:radio[class=radiobutton]:checked").attr("dataval"); var ddlAllTemplates = $('#ddlAllTemplates'); var options = ddlAllTemplates.find('option'); $('#ddlAllTemplates option').each(function () { var extract = $(this).attr('value').split('|')[2]; if (extract == templateType) $(this).show(); else $(this).hide(); }); }); </code></pre>
 

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