title: Radio Button filter using jquery/javascript
body: <p>There is an HTML table which contains two column(Source and Type). To filter the data, there are two radio buttons. I am able to filter the data for each radio button but I am struggling to combine the two radio button filter functions. </p>
  
  <p>HTML Code</p>
  
  <pre><code>&lt;form action="" id="Details"&gt;
  &lt;fieldset&gt;
  &lt;label&gt;&lt;input type="radio" name="Option1" value="Critical" &gt;Critical&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="Option1" value="Non Critical" &gt;Non Critical&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="Option1" value="A" checked="checked" &gt;All&lt;/label&gt;
      &lt;br&gt;
      &lt;br&gt;
  &lt;label&gt;&lt;input type="radio" name="Option2" value="Internal" &gt;Internal&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="Option2" value="External" &gt;External&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="Option2" value="A" checked="checked" &gt;All&lt;/label&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;br&gt;
      &lt;br&gt;
  &lt;div&gt;
          &lt;table id="DataTable"  border="1"&gt;
          &lt;tr&gt;
          &lt;th&gt;Source&lt;/th&gt;
          &lt;th&gt;Type&lt;/th&gt;
          &lt;/tr&gt;            
          &lt;tr&gt;
          &lt;td class="Source"&gt;Internal&lt;/td&gt;
          &lt;td  class="Type"&gt;Critical&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td  class="Source"&gt;Internal&lt;/td&gt;
          &lt;td class="Type"&gt;Non Critical&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td class="Source"&gt;External&lt;/td&gt;
          &lt;td class="Type"&gt;Critical&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td class="Source"&gt;External&lt;/td&gt;
          &lt;td class="Type"&gt;Non Critical&lt;/td&gt;
          &lt;/tr&gt;       
          &lt;/table&gt;
  &lt;/div&gt;
   &lt;button id='btnFilter'&gt;Go&lt;/button&gt;       
  </code></pre>
  
  <p>Script</p>
  
  <pre><code>$('#btnFilter').click(function() {
  
      var val1 = $('[name=Option1]:checked').val();
      var val2 = $('[name=Option2]:checked').val();
  
  
      $('tr').hide();
  
      $('tr td.Source').each(function() {
  
          if ($(this).text() == val2 )
          {
  
              $(this).parent().show();
          }
      });
      alert("ok");
      $('tr').hide();
          $('tr td.Type').each(function() {
  
          if ($(this).text() == val1 )
          {
  
              $(this).parent().show();
          }
      });
  
  });
  </code></pre>
  
  <p>Expected Behavior
  User will select both radio button values(if not selected then default values will be considered) and then HTML table should be filtered considered both the selected valued.If user changes value of one radio button, the HTML table should be filtered accordingly.
  In my code, each filter logic works fine but I am not able to combine both the logics i.e. If am applying the filter for second radio button then it should take data which is filtered by first radio button and apply show/hide on top of that but when i do it considers whole data. </p>
  
  <p>Current logic is <strong><a href="http://jsfiddle.net/anjsfiddle/ZxUUA/2/" rel="nofollow">Fiddle</a></strong></p>
  
  <p>Also, When users selects all from any radio buttons then it means all data should be considered wrt to that radio button. If both All are selected then whole HTML table data.</p>